Module: Rspec::ApiHelpers::ExampleGroupMethods
- Defined in:
- lib/rspec/api_helpers/example_group_methods.rb
Instance Method Summary collapse
-
#it_includes_in_headers(headers = {}) ⇒ Object
make rehashable.
- #it_returns_attribute_values(options = {}) ⇒ Object (also: #it_returns_more_attribute_values)
-
#it_returns_collection_attribute_values(options = {}) ⇒ Object
finds_by id.
- #it_returns_collection_attributes(options = {}) ⇒ Object (also: #it_returns_more_collection_attributes)
- #it_returns_collection_size(options = {}) ⇒ Object
- #it_returns_no_attributes(options = {}) ⇒ Object
- #it_returns_no_collection_attributes(options = {}) ⇒ Object
- #it_returns_status(status) ⇒ Object
Instance Method Details
#it_includes_in_headers(headers = {}) ⇒ Object
make rehashable
11 12 13 14 15 16 17 |
# File 'lib/rspec/api_helpers/example_group_methods.rb', line 11 def it_includes_in_headers(headers = {}) headers.each do |header, value| it "returns headers #{header} wih value: #{value}" do expect(last_response.headers[header.to_s]).to eq(eval(value)) end end end |
#it_returns_attribute_values(options = {}) ⇒ Object Also known as: it_returns_more_attribute_values
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rspec/api_helpers/example_group_methods.rb', line 19 def it_returns_attribute_values( = {}) it "expects returned resource (#{[:resource]}) to have model attribute values" do resource = dispatcher.adapter.resource(.merge(existing: true), last_response, self) #support proc on attrs [:attrs].each do |attribute| begin resource.compare_attribute(attribute) rescue RSpec::Expectations::ExpectationNotMetError => e e. << "failed at model attribute: #{attribute}" raise e end end end end |
#it_returns_collection_attribute_values(options = {}) ⇒ Object
finds_by id
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/rspec/api_helpers/example_group_methods.rb', line 100 def it_returns_collection_attribute_values( = {}) it "expects returned collection (#{[:resource]}) to have model attribute values" do resource = dispatcher.adapter.collection( , last_response, self ).find_by(:id, existing: true, resource: nil) #support proc on attrs [:attrs].each do |attribute| begin resource.compare_attribute(attribute) rescue RSpec::Expectations::ExpectationNotMetError => e e. << "failed at model attribute: #{attribute}" raise e end end end end |
#it_returns_collection_attributes(options = {}) ⇒ Object Also known as: it_returns_more_collection_attributes
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rspec/api_helpers/example_group_methods.rb', line 59 def it_returns_collection_attributes( = {}) it "returns the correct attributes (no value checking) for resources in the #{[:resource]} collection" do sample_resource = dispatcher.adapter.collection( , last_response, self ).sample(existing: true, resource: nil) #support proc on attrs [:attrs].each do |attribute| begin sample_resource.has_attribute(attribute) rescue RSpec::Expectations::ExpectationNotMetError => e e. << "failed at model attribute: #{attribute}" raise e end end end end |
#it_returns_collection_size(options = {}) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/rspec/api_helpers/example_group_methods.rb', line 51 def it_returns_collection_size( = {}) it "returns the correct number of resources in the #{[:resource]} collection" do collection = dispatcher.adapter.collection(.merge(existing: true), last_response, self) collection.has_size([:size]) end end |
#it_returns_no_attributes(options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rspec/api_helpers/example_group_methods.rb', line 36 def it_returns_no_attributes( = {}) it "expects returned resource (#{[:root]}) to NOT have the following attributes" do resource = dispatcher.adapter.resource(.merge(existing: false), last_response, self) [:attrs].each do |attribute| begin resource.has_no_attribute(attribute) rescue RSpec::Expectations::ExpectationNotMetError => e e. << "failed at model attribute: #{attribute}" raise e end end end end |
#it_returns_no_collection_attributes(options = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rspec/api_helpers/example_group_methods.rb', line 81 def it_returns_no_collection_attributes( = {}) it "expects returned collection (#{[:resource]}) to NOT have the following attributes" do sample_resource = dispatcher.adapter.collection( , last_response, self ).sample(existing: false, resource: nil) #support proc on attrs [:attrs].each do |attribute| begin sample_resource.has_no_attribute(attribute) rescue RSpec::Expectations::ExpectationNotMetError => e e. << "failed at model attribute: #{attribute}" raise e end end end end |
#it_returns_status(status) ⇒ Object
4 5 6 7 8 |
# File 'lib/rspec/api_helpers/example_group_methods.rb', line 4 def it_returns_status(status) it "returns the correct HTTP status (status: #{status})" do expect(last_response.status).to eql(status) end end |