Module: RSpec::Resources::DSL::Matchers

Extended by:
ActiveSupport::Concern
Defined in:
lib/rspec/resources/dsl/matchers.rb,
lib/rspec/resources/dsl/matchers/error_matcher.rb,
lib/rspec/resources/dsl/matchers/json_model_matcher.rb

Defined Under Namespace

Classes: ErrorMatcher, JsonModelMatcher

Instance Method Summary collapse

Instance Method Details

#creates_a_new_record(check: nil) ⇒ Object



39
40
41
42
43
44
45
# 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_subjectObject



53
54
55
56
57
# 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) ⇒ Object



51
52
53
# 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) ⇒ Object



55
56
57
# 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) ⇒ Object



45
46
47
48
49
50
# 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) ⇒ Object



52
53
54
# 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) ⇒ Object



12
13
14
# 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) ⇒ Object

Return Validators ###



20
21
22
23
24
25
26
27
28
# 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_subjectObject



30
31
32
33
34
35
36
37
# 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) ⇒ Object



47
48
49
50
51
# 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