Confused by assert_select code generated by edit_spec.rb #664

tovodeverett opened this Issue Jan 4, 2013 · 3 comments


None yet

3 participants

I'm confused by the assert_select code generated by rspec-rails/lib/generators/rspec/scaffold/templates/edit_spec.rb and new_spec.rb.

Specifically, it generates code like this:

assert_select "form", :action => foos_path(@foo), :method => "post" do

I can't find any documentation for the :action and :method options for ActionDispatch::Assertions::SelectorAssertions#assert_select. Furthermore, mangling the values for those options doesn't seem to have any impact on whether the assertion succeeds or not, leading me to believe those options don't actually do anything.

It looks like ActionDispatch::Assertions::SelectorAssertions#assert_select eventually assigns the hash to equals (from which it does use the :text, :html, :count, etc. options), but it never calls assert_valid_keys on equals. Which explains why it doesn't complain about the invalid options, thus allowing the scaffold code to continue to appear to test something it's not actually testing.

On the other hand, it is entirely conceivable that I'm just really confused, and if so I apologize!


@dchelimsky, do you know anything about assert_select taking these arguments? It looks like the scaffold generator started including them during a refactor related to webrat, but I came late enough to the game that I'm not familiar with it. I will dig if needed, but thought you might know offhand.


Actually, I just found, which has this example at the bottom:

assert_select "html:root>head>title", "Login"
assert_select "form[action=?]", url_for(:action=>"login") do
  assert_select "input[type=text][name=username]"
  assert_select "input[type=password][name=password]"

So the generated code might have been a typo based on :action => "login" without wrapping it in url_for. Just guessing.


Thanks @dchelimsky, that makes more sense. After digging a bit more myself, I've improved the specs that will be generated by scaffolding.

@alindeman alindeman closed this in 75ea1ec Feb 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment