Skip to content

Commit

Permalink
Polish failure messages
Browse files Browse the repository at this point in the history
  • Loading branch information
MDaubs authored and Gabe Berke-Williams committed Mar 23, 2012
1 parent 00a9a68 commit 558d1df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/shoulda/matchers/active_record/query_the_database_matcher.rb
Expand Up @@ -67,11 +67,17 @@ def failure_message
if @expected_query_count
"Expected ##{@method_name} to cause #{@expected_query_count} database queries but it actually caused #{@queries.length} queries:" + friendly_queries
else
"Expected ##{@method_name} to not query the database but it actually caused #{@queries.length} queries:" + friendly_queries
"Expected ##{@method_name} to query the database but it actually caused #{@queries.length} queries:" + friendly_queries
end
end

alias_method :negative_failure_message, :failure_message
def negative_failure_message
if @expected_query_count
"Expected ##{@method_name} to not cause #{@expected_query_count} database queries but it actually caused #{@queries.length} queries:" + friendly_queries
else
"Expected ##{@method_name} to not query the database but it actually caused #{@queries.length} queries:" + friendly_queries
end
end

private

Expand Down
8 changes: 8 additions & 0 deletions spec/shoulda/active_record/query_the_database_matcher_spec.rb
Expand Up @@ -17,6 +17,14 @@
@parent.should query_the_database(1.times).when_calling(:count)
end

it "should accept any number of queries when none specified" do
@parent.should query_the_database.when_calling(:count)
end

it "should reject any number of queries when non specified" do
@parent.should_not query_the_database.when_calling(:to_s)
end

it "should accept the correct number of queries when there are two queries" do
nonsense = lambda do
@parent.create.kittens.create
Expand Down

0 comments on commit 558d1df

Please sign in to comment.