module RSpec::Resources::DSL::Matchers
Public Instance Methods
creates_a_new_record(check: nil)
click to toggle source
# File lib/rspec/resources/dsl/matchers.rb, line 39 def creates_a_new_record(check: nil) try_set_description 'creates a new record with the given attributes' record = accessible_resource.class.find_by_id(Util.access_by_path(base_doc, id_path)) expect(record).to be_present expect(record).to match_params(check || params) end
destroys_the_subject()
click to toggle source
# File lib/rspec/resources/dsl/matchers.rb, line 53 def destroys_the_subject try_set_description 'deletes the record' expect(subject.class.find_by_id(subject.id)).to be_nil end
equal_record(record, hash)
click to toggle source
# File lib/rspec/resources/dsl/matchers/json_model_matcher.rb, line 51 def equal_record(record, hash) JsonModelMatcher.new(record, hash[:on]) end
match_params(iparams)
click to toggle source
# File lib/rspec/resources/dsl/matchers/json_model_matcher.rb, line 55 def match_params(iparams) JsonModelMatcher.new(iparams, iparams.keys) end
return_an_error(hash)
click to toggle source
# File lib/rspec/resources/dsl/matchers/error_matcher.rb, line 45 def return_an_error(hash) code = hash[:with_code] msg = hash[:with_message] || hash[:and_message] ErrorMatcher.new(code, msg) end
returns_an_error(hash)
click to toggle source
# File lib/rspec/resources/dsl/matchers/error_matcher.rb, line 52 def returns_an_error(hash) expect(response).to return_an_error(hash) end
returns_status_code(code)
click to toggle source
# File lib/rspec/resources/dsl/matchers.rb, line 12 def returns_status_code(code) expect(response).to have_http_status(code) end
returns_the_records(*records)
click to toggle source
Return Validators ###
# File lib/rspec/resources/dsl/matchers.rb, line 20 def returns_the_records(*records) try_set_description 'returns the requested records' expect(base_doc.length).to eq(records.length) base_doc.each_with_index do |jd, i| check_document jd, to_match: records[i] end end
returns_the_subject()
click to toggle source
# File lib/rspec/resources/dsl/matchers.rb, line 30 def returns_the_subject if subject.is_a? Array returns_the_records(*subject) else try_set_description 'returns the requested record' check_document base_doc, to_match: subject end end
updates_the_subject(check: nil)
click to toggle source
# File lib/rspec/resources/dsl/matchers.rb, line 47 def updates_the_subject(check: nil) try_set_description 'updates the record with the given attributes' expect(subject.reload).to match_params(check || params) end
Private Instance Methods
attributes_doc_path()
click to toggle source
# File lib/rspec/resources/dsl/matchers.rb, line 85 def attributes_doc_path Util.document_format_hash[:attributes_path] end
base_doc()
click to toggle source
# File lib/rspec/resources/dsl/matchers.rb, line 81 def base_doc Util.access_by_path(json_body, Util.document_format_hash[:base_path]) end
check_document(doc, to_match: nil)
click to toggle source
# File lib/rspec/resources/dsl/matchers.rb, line 61 def check_document(doc, to_match: nil) # check presence of attributes expect(Util.access_by_path(doc, attributes_doc_path)).to equal_record(to_match, on: visible_attributes) # check absence of attributes return unless defined?(hidden_attributes) hidden_attributes.each do |a| expect(doc).not_to have_key(a.to_s) end end
id_path()
click to toggle source
# File lib/rspec/resources/dsl/matchers.rb, line 89 def id_path Util.document_format_hash[:id_path] end
json_body()
click to toggle source
# File lib/rspec/resources/dsl/matchers.rb, line 77 def json_body JSON.parse(response.body) end
try_set_description(desc)
click to toggle source
# File lib/rspec/resources/dsl/matchers.rb, line 72 def try_set_description(desc) return if RSpec.current_example.metadata[:description].present? RSpec.current_example.metadata[:description] = desc end