From 4381e59a35e0489c9879f84751274df3a8ddae44 Mon Sep 17 00:00:00 2001 From: Phil Date: Thu, 10 Mar 2016 11:30:32 -0800 Subject: [PATCH 1/2] ActionHandlerMatchers.failure_message more information Rather than saying "the class" specify the exact class name that is expected to return the action. Could be useful when generating large amount of tests dynamically. --- lib/resource_kit/testing/action_handler_matchers.rb | 4 ++-- .../testing/action_handler_matchers_spec.rb | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/resource_kit/testing/action_handler_matchers.rb b/lib/resource_kit/testing/action_handler_matchers.rb index b8452be..4dd0a40 100644 --- a/lib/resource_kit/testing/action_handler_matchers.rb +++ b/lib/resource_kit/testing/action_handler_matchers.rb @@ -22,13 +22,13 @@ def matches?(subject, &block) @handled_block ||= block action = subject.resources.find_action(self.action) unless action - @failure_message = "expected :#{self.action} to be handled by the class." + @failure_message = "expected :#{self.action} to be handled by #{subject.class.name}." return false end status_code = response_stub.status || 200 unless action.handlers[status_code] - @failure_message = "expected the #{status_code} status code to be handled by the class." + @failure_message = "expected the #{status_code} status code to be handled by #{subject.class.name}." return false end diff --git a/spec/lib/resource_kit/testing/action_handler_matchers_spec.rb b/spec/lib/resource_kit/testing/action_handler_matchers_spec.rb index 4e6c5e7..e7edaec 100644 --- a/spec/lib/resource_kit/testing/action_handler_matchers_spec.rb +++ b/spec/lib/resource_kit/testing/action_handler_matchers_spec.rb @@ -39,8 +39,12 @@ end describe '#failure_message' do + before(:each) do + allow(resource_class.class).to receive(:name).and_return("CustomClassName") + end + context "when the matchers doesnt handle the same status code" do - it 'returns "expected the #{status_code} status code to be handled by the class."' do + it 'returns "expected the #{status_code} status code to be handled by CustomClassName."' do resource_class.resources.action :all, 'GET /all' do handler(200) { |response| JSON.load(response.body) } end @@ -48,12 +52,12 @@ matcher.with(status: 201, body: '{"Hello": "World"}') matcher.matches?(resource_class) { } - expect(matcher.failure_message).to eq('expected the 201 status code to be handled by the class.') + expect(matcher.failure_message).to eq('expected the 201 status code to be handled by CustomClassName.') end end context "when the matchers doesnt handle the same status code" do - it 'returns "expected the #{status_code} status code to be handled by the class."' do + it 'returns "expected the #{status_code} status code to be handled by CustomClassName."' do resource_class.resources.action :show, 'GET /all' do handler(200) { |response| JSON.load(response.body) } end @@ -61,7 +65,7 @@ matcher.with(status: 200, body: '{"Hello": "World"}') matcher.matches?(resource_class) { } - expect(matcher.failure_message).to eq('expected :all to be handled by the class.') + expect(matcher.failure_message).to eq('expected :all to be handled by CustomClassName.') end end end From dc09fbe21dc866e6306dcc47fa59aac64e024935 Mon Sep 17 00:00:00 2001 From: Phil Date: Thu, 10 Mar 2016 11:35:01 -0800 Subject: [PATCH 2/2] Fix the fact that it should be a Class passed in, not an instance --- lib/resource_kit/testing/action_handler_matchers.rb | 4 ++-- spec/lib/resource_kit/testing/action_handler_matchers_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/resource_kit/testing/action_handler_matchers.rb b/lib/resource_kit/testing/action_handler_matchers.rb index 4dd0a40..477e89d 100644 --- a/lib/resource_kit/testing/action_handler_matchers.rb +++ b/lib/resource_kit/testing/action_handler_matchers.rb @@ -22,13 +22,13 @@ def matches?(subject, &block) @handled_block ||= block action = subject.resources.find_action(self.action) unless action - @failure_message = "expected :#{self.action} to be handled by #{subject.class.name}." + @failure_message = "expected :#{self.action} to be handled by #{subject.name}." return false end status_code = response_stub.status || 200 unless action.handlers[status_code] - @failure_message = "expected the #{status_code} status code to be handled by #{subject.class.name}." + @failure_message = "expected the #{status_code} status code to be handled by #{subject.name}." return false end diff --git a/spec/lib/resource_kit/testing/action_handler_matchers_spec.rb b/spec/lib/resource_kit/testing/action_handler_matchers_spec.rb index e7edaec..64800d5 100644 --- a/spec/lib/resource_kit/testing/action_handler_matchers_spec.rb +++ b/spec/lib/resource_kit/testing/action_handler_matchers_spec.rb @@ -40,7 +40,7 @@ describe '#failure_message' do before(:each) do - allow(resource_class.class).to receive(:name).and_return("CustomClassName") + allow(resource_class).to receive(:name).and_return("CustomClassName") end context "when the matchers doesnt handle the same status code" do