class Object
Public Instance Methods
is_optional(*params)
click to toggle source
# File lib/restpack_service/support/matchers.rb, line 12 def is_optional(*params) params.each do |param| it ":#{param} parameter must be required" do expect(subject.class.input_filters.optional_inputs).to include(param) end end end
is_required(*params)
click to toggle source
# File lib/restpack_service/support/matchers.rb, line 4 def is_required(*params) params.each do |param| it ":#{param} parameter must be required" do expect(subject.class.input_filters.required_inputs).to include(param) end end end
it_acts_as_create_command()
click to toggle source
# File lib/restpack_service/support/matchers/create_command.rb, line 1 def it_acts_as_create_command let(:response) { subject.class.run(params) } let(:resource_plural) { subject.Serializer.plural_key } let(:resource_singular) { subject.Serializer.singular_key } context "with valid params" do context "when creating a single item" do let(:item) { build("api_#{resource_singular}") } let(:params) { { resource_plural => [item] } } it_succeeds "and returns the newly created resource" do expect(response.result).to include(resource_plural), "The reponse should include an array of :#{resource_plural}" response_items = response.result[resource_plural] expect(response_items.length).to eq(1) response_item = response_items.first model = subject.Model.find(response_item[:id]) expect(response_item).to eq(subject.Serializer.as_json(model)) end end end context "when creating multiple items" do let(:item1) { build("api_#{resource_singular}".to_sym) } let(:item2) { build("api_#{resource_singular}".to_sym) } let(:params) { { resource_plural => [item1, item2] } } it_succeeds "and returns the newly created resources" do expect(response.result).to include(resource_plural), "The reponse should include an array of :#{resource_plural}" response_items = response.result[resource_plural] expect(response_items.length).to eq(2) response_items.each do |response_item| model = subject.Model.find(response_item[:id]) expect(response_item).to eq(subject.Serializer.as_json(model)) end end end end
it_fails_with(status, &block)
click to toggle source
# File lib/restpack_service/support/matchers.rb, line 37 def it_fails_with(status, &block) it "fails with :#{status}" do expect(response.success?).to eq(false) expect(response.result).to eq({}) expect(response.status).to eq(status) instance_eval(&block) if block_given? end end
it_succeeds(message='succeeds', &block)
click to toggle source
# File lib/restpack_service/support/matchers.rb, line 46 def it_succeeds(message='succeeds', &block) it message do expect(response.success?).to eq(true) instance_eval(&block) if block_given? end end
service_request_with(param, value) { |result| ... }
click to toggle source
Calls superclass method
# File lib/restpack_service/support/matchers.rb, line 20 def service_request_with(param, value, &block) context "when :#{param} = #{value.inspect}" do let(:params) do super().merge({ param => value }) end it { yield(response.result) } end end
service_should_map(param, map)
click to toggle source
# File lib/restpack_service/support/matchers.rb, line 29 def service_should_map(param, map) context param do map.each do |value, expected| service_request_with(param, value) { |r| r[param].should == expected } end end end
setup()
click to toggle source
# File lib/restpack_service/support/spec_helper.rb, line 10 def setup config = YAML.load_file('./config/database.yml') ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'] || config['test']) migrations = ActiveRecord::Migrator.up('./db/migrate') FactoryGirl.find_definitions DatabaseCleaner.strategy = :transaction RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods config.before(:each) do DatabaseCleaner.start end config.after(:each) do DatabaseCleaner.clean end end end