diff --git a/lib/resource_kit/testing/action_handler_matchers.rb b/lib/resource_kit/testing/action_handler_matchers.rb index b8452be..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 the class." + @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 the class." + @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 4e6c5e7..64800d5 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).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