Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Confused by assert_select code generated by edit_spec.rb #664

Closed
tovodeverett opened this Issue · 3 comments

3 participants

Toby Ovod-Everett alindeman David Chelimsky
Toby Ovod-Everett

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
end

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!

alindeman
Collaborator

@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.

David Chelimsky
Owner

Actually, I just found http://content.labnotes.org/assert_select/assert_select.html, 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]"
end

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

alindeman
Collaborator

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.