module Rspec::ApiHelpers::ExampleGroupMethods

Public Instance Methods

it_includes_in_headers(headers = {}) click to toggle source

make rehashable

# 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 = {}) click to toggle source
# File lib/rspec/api_helpers/example_group_methods.rb, line 19
def it_returns_attribute_values(options = {})
  it "expects returned resource (#{options[:resource]}) to have model attribute values" do
    resource = dispatcher.adapter.resource(options.merge(existing: true), last_response, self)

    #support proc on attrs
    options[:attrs].each do |attribute|
      begin
        resource.compare_attribute(attribute)
      rescue RSpec::Expectations::ExpectationNotMetError => e
        e.message << "failed at model attribute: #{attribute}"
        raise e
      end
    end
  end
end
it_returns_collection_attribute_values(options = {}) click to toggle source

finds_by id

# File lib/rspec/api_helpers/example_group_methods.rb, line 100
def it_returns_collection_attribute_values(options = {})
  it "expects returned collection (#{options[:resource]}) to have model attribute values" do
    resource = dispatcher.adapter.collection(
      options, last_response, self
    ).find_by(:id, existing: true, resource: nil)

    #support proc on attrs
    options[:attrs].each do |attribute|
      begin
        resource.compare_attribute(attribute)
      rescue RSpec::Expectations::ExpectationNotMetError => e
        e.message << "failed at model attribute: #{attribute}"
        raise e
      end
    end
  end
end
it_returns_collection_attributes(options = {}) click to toggle source
# File lib/rspec/api_helpers/example_group_methods.rb, line 59
def it_returns_collection_attributes(options = {})
  it "returns the correct attributes (no value checking) for resources in the #{options[:resource]} collection" do
    sample_resource = dispatcher.adapter.collection(
      options, last_response, self
    ).sample(existing: true, resource: nil)

    #support proc on attrs
    options[:attrs].each do |attribute|
      begin
        sample_resource.has_attribute(attribute)
      rescue RSpec::Expectations::ExpectationNotMetError => e
        e.message << "failed at model attribute: #{attribute}"
        raise e
      end
    end
  end
end
it_returns_collection_size(options = {}) click to toggle source
# File lib/rspec/api_helpers/example_group_methods.rb, line 51
def it_returns_collection_size(options = {})
  it "returns the correct number of resources in the #{options[:resource]} collection" do
    collection = dispatcher.adapter.collection(options.merge(existing: true), last_response, self)

    collection.has_size(options[:size])
  end
end
it_returns_more_attribute_values(options = {})
it_returns_more_collection_attributes(options = {})
it_returns_no_attributes(options = {}) click to toggle source
# File lib/rspec/api_helpers/example_group_methods.rb, line 36
def it_returns_no_attributes(options = {})
  it "expects returned resource (#{options[:root]}) to NOT have the following attributes" do
    resource = dispatcher.adapter.resource(options.merge(existing: false), last_response, self)

    options[:attrs].each do |attribute|
      begin
        resource.has_no_attribute(attribute)
      rescue RSpec::Expectations::ExpectationNotMetError => e
        e.message << "failed at model attribute: #{attribute}"
        raise e
      end
    end
  end
end
it_returns_no_collection_attributes(options = {}) click to toggle source
# File lib/rspec/api_helpers/example_group_methods.rb, line 81
def it_returns_no_collection_attributes(options = {})
  it "expects returned collection (#{options[:resource]}) to NOT have the following attributes" do
    sample_resource = dispatcher.adapter.collection(
      options, last_response, self
    ).sample(existing: false, resource: nil)

    #support proc on attrs
    options[:attrs].each do |attribute|
      begin
        sample_resource.has_no_attribute(attribute)
      rescue RSpec::Expectations::ExpectationNotMetError => e
        e.message << "failed at model attribute: #{attribute}"
        raise e
      end
    end
  end
end
it_returns_status(status) click to toggle source
# 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