Module: RocketPants::RSpecMatchers
- Extended by:
- RSpec::Matchers::DSL
- Defined in:
- lib/rocket_pants/rspec_matchers.rb
Class Method Summary collapse
- .differ ⇒ Object
-
.normalise_as_json(object, options = {}) ⇒ Object
Converts it to JSON and back again.
- .normalise_response(response, options = {}) ⇒ Object
- .normalise_urls(object) ⇒ Object
- .normalised_error(e) ⇒ Object
- .valid_for?(response, allowed, disallowed) ⇒ Boolean
Instance Method Summary collapse
Class Method Details
.differ ⇒ Object
42 43 44 |
# File 'lib/rocket_pants/rspec_matchers.rb', line 42 def self.differ @_differ ||= RSpec::Expectations::Differ.new end |
.normalise_as_json(object, options = {}) ⇒ Object
Converts it to JSON and back again.
23 24 25 26 27 28 |
# File 'lib/rocket_pants/rspec_matchers.rb', line 23 def self.normalise_as_json(object, = {}) = .reverse_merge(:compact => true) if object.is_a?(Array) object = RocketPants::Respondable.normalise_object(object, ) j = ActiveSupport::JSON j.decode(j.encode({'response' => object}))['response'] end |
.normalise_response(response, options = {}) ⇒ Object
30 31 32 |
# File 'lib/rocket_pants/rspec_matchers.rb', line 30 def self.normalise_response(response, = {}) normalise_urls normalise_as_json response, end |
.normalise_urls(object) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/rocket_pants/rspec_matchers.rb', line 13 def self.normalise_urls(object) if object.is_a?(Array) object.each { |o| o['url'] = nil } elsif object.is_a?(Hash) || (defined?(APISmith::Smash) && object.is_a?(APISmith::Smash)) object['url'] = nil end object end |
.normalised_error(e) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/rocket_pants/rspec_matchers.rb', line 5 def self.normalised_error(e) if e.is_a?(String) || e.is_a?(Symbol) Errors[e] else e end end |
.valid_for?(response, allowed, disallowed) ⇒ Boolean
34 35 36 37 38 39 40 |
# File 'lib/rocket_pants/rspec_matchers.rb', line 34 def self.valid_for?(response, allowed, disallowed) body = response.decoded_body return false if body.blank? body = body.to_hash return false if body.has_key?("error") allowed.all? { |f| body.has_key?(f) } && !disallowed.any? { |f| body.has_key?(f) } end |
Instance Method Details
#be_api_error(error = nil) ⇒ Object
111 112 113 |
# File 'lib/rocket_pants/rspec_matchers.rb', line 111 def be_api_error(error = nil) _be_api_error error end |