Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/resource_kit/testing/action_handler_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 8 additions & 4 deletions spec/lib/resource_kit/testing/action_handler_matchers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,33 @@
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

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

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
Expand Down