#159 - Excute batch requests using the service's connection
[arvados.git] / spec / spec_helper.rb
1 $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2 $LOAD_PATH.uniq!
3
4 require 'rspec'
5 require 'faraday'
6
7 begin
8   require 'simplecov'
9
10   SimpleCov.start
11 rescue LoadError
12   # SimpleCov missing, so just run specs with no coverage.
13 end
14
15 Faraday::Adapter.load_middleware(:test)
16
17 module Faraday
18   class Connection
19     def verify
20       if app.kind_of?(Faraday::Adapter::Test)
21         app.stubs.verify_stubbed_calls
22       else
23         raise TypeError, "Expected test adapter"
24       end
25     end
26   end
27 end
28
29 module ConnectionHelpers
30   def stub_connection(&block)
31     stubs = Faraday::Adapter::Test::Stubs.new do |stub|
32       block.call(stub)
33     end
34     connection = Faraday.new do |builder|
35       builder.options.params_encoder = Faraday::FlatParamsEncoder
36       builder.adapter(:test, stubs)
37     end
38   end
39 end
40
41 module JSONMatchers
42   class EqualsJson
43     def initialize(expected)
44       @expected = JSON.parse(expected)
45     end
46     def matches?(target)
47       @target = JSON.parse(target)
48       @target.eql?(@expected)
49     end
50     def failure_message
51       "expected #{@target.inspect} to be #{@expected}"
52     end
53     def negative_failure_message
54       "expected #{@target.inspect} not to be #{@expected}"
55     end
56   end
57
58   def be_json(expected)
59     EqualsJson.new(expected)
60   end
61 end
62
63 RSpec.configure do |config|
64 end