21224: fixed description width
[arvados.git] / sdk / ruby-google-api-client / 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   require 'coveralls'
10
11   SimpleCov.formatter = Coveralls::SimpleCov::Formatter
12   SimpleCov.start
13 rescue LoadError
14   # SimpleCov missing, so just run specs with no coverage.
15 end
16
17 Faraday::Adapter.load_middleware(:test)
18
19 module Faraday
20   class Connection
21     def verify
22       if app.kind_of?(Faraday::Adapter::Test)
23         app.stubs.verify_stubbed_calls
24       else
25         raise TypeError, "Expected test adapter"
26       end
27     end
28   end
29 end
30
31 module ConnectionHelpers
32   def stub_connection(&block)
33     stubs = Faraday::Adapter::Test::Stubs.new do |stub|
34       block.call(stub)
35     end
36     connection = Faraday.new do |builder|
37       builder.options.params_encoder = Faraday::FlatParamsEncoder
38       builder.adapter(:test, stubs)
39     end
40   end
41 end
42
43 module JSONMatchers
44   class EqualsJson
45     def initialize(expected)
46       @expected = JSON.parse(expected)
47     end
48     def matches?(target)
49       @target = JSON.parse(target)
50       @target.eql?(@expected)
51     end
52     def failure_message
53       "expected #{@target.inspect} to be #{@expected}"
54     end
55     def negative_failure_message
56       "expected #{@target.inspect} not to be #{@expected}"
57     end
58   end
59
60   def be_json(expected)
61     EqualsJson.new(expected)
62   end
63 end
64
65 RSpec.configure do |config|
66 end