This project is archived and is in readonly mode.
assert_select gives misleading message
-
David Trasbo
This issue can be duplicated with Rails 2.3.5 and edge Rails:
2.3.5:
➜ code rails -v Rails 2.3.5 ➜ code rails assert_select ... ➜ code cd assert_select ➜ assert_select script/generate controller foos ... ➜ assert_select rake db:migrate (in /Users/dtrasbo/code/assert_select) ➜ assert_select rake test:functionals (in /Users/dtrasbo/code/assert_select) /Users/dtrasbo/.rvm/rubies/ruby-1.8.7-p249/bin/ruby -I"lib:test" "/Users/dtrasbo/.rvm/gems/ruby-1.8.7-p249@global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/functional/foos_controller_test.rb" Loaded suite /Users/dtrasbo/.rvm/gems/ruby-1.8.7-p249@global/gems/rake-0.8.7/lib/rake/rake_test_loader Started F Finished in 0.042935 seconds. 1) Failure: test_assert_select(FoosControllerTest) [/test/functional/foos_controller_test.rb:7]: Expected at least 7 elements matching "a", found 5. <false> is not true. 1 tests, 1 assertions, 1 failures, 0 errors rake aborted! Command failed with status (1): [/Users/dtrasbo/.rvm/rubies/ruby-1.8.7-p249...] (See full trace by running task with --trace)Edge:
➜ code ruby rails/bin/rails assert_select --dev ... ➜ code cd assert_select ➜ assert_select ruby ../rails/bin/rails g controller foos index ... ➜ assert_select rake db:migrate (in /Users/dtrasbo/code/assert_select) ➜ assert_select rake test:functionals (in /Users/dtrasbo/code/assert_select) Loaded suite /Users/dtrasbo/.rvm/gems/ruby-1.8.7-p249@global/gems/rake-0.8.7/lib/rake/rake_test_loader Started F Finished in 0.107355 seconds. 1) Failure: test_assert_select(FoosControllerTest) [/test/functional/foos_controller_test.rb:6]: Expected at least 2 elements matching "a", found 1. <false> is not true. 1 tests, 1 assertions, 1 failures, 0 errors rake aborted! Command failed with status (1): [/Users/dtrasbo/.rvm/rubies/ruby-1.8.7-p249...] (See full trace by running task with --trace)Both:
require 'test_helper' class FoosControllerTest < ActionController::TestCase # Replace this with your real tests. test "assert_select" do get :index assert_select 'a', 7 end endPatch welcome.
-
Lenary
david, your outputs are confusing. did you really use the same tests for both of them?
rails 3:
Expected at least 7 elements matching "a", found 5.rails 3:
Expected at least 2 elements matching "a", found 1. -
Rizwan Reza
- Tag changed from assert_select, testing to assert_select, bugmash, testing
Here is the relevant code:
Expected #{count_description(min, max)} matching "#{selector.to_s}", found #{matches.size}.I think it's okay for me. ;)
-
PacoGuzman
In the explanation of the assert_select method we have:
# === Equality Tests # # The equality test may be one of the following: # * <tt>true</tt> - Assertion is true if at least one element selected. # * <tt>false</tt> - Assertion is true if no element selected. # * <tt>String/Regexp</tt> - Assertion is true if the text value of at least # one element matches the string or regular expression. # * <tt>Integer</tt> - Assertion is true if exactly that number of # elements are selected. # * <tt>Range</tt> - Assertion is true if the number of selected # elements fit the range. # If no equality test specified, the assertion is true if at least one # element selectedSo, if we use an Integer like Jarl did I think the error message not correspond to the description of the behaviour of the method.
I'll work to fix this, What do you think?
-
PacoGuzman
I've attached a patch
Now, when use assert_select with false or Integer for the equality test the error message would be more accurate, for example:
Expected exactly 5 elements matching "a", found 8.
-
Jeff Kreeftmeijer
+1
Applies to master cleanly, all tests pass.
-
pleax
+1
Patch applies cleanly, well tested and all tests pass.
-
Rizwan Reza
- Milestone cleared.
- Tag changed from assert_select, bugmash, testing to assert_select, bugmash, patch, testing
- State changed from new to verified
- Assigned user set to Yehuda Katz (wycats)
-
José Valim
- State changed from verified to committed
- Assigned user changed from Yehuda Katz (wycats) to José Valim
Applied.
-
Rizwan Reza
- Tag changed from assert_select, bugmash, patch, testing to assert_select, patch, testing
