tags:

views:

56

answers:

2

I am trying to write specs for the posts/show.html.erb view of a simple application I'm putting together to learn rspec. I'm a bit stumped at the moment on trying to figure out where the extra "%2F" is coming from. Any ideas?

My spec...

  it "should render a form to add a comment" do
    render "posts/show.html.erb"
    response.should have_selector("form[method=post]", :action => post_comments_path([@post, @comment])) do |form|
      form.should have_selector("input[name='comment[author_name]']")
      form.should have_selector("textarea[name='comment[body]']")
      form.should have_selector("input[type=submit]")
    end
  end

The spec output with the extra %2F...

'posts/show.html.erb should render a form to add a comment' FAILED
expected following output to contain a <form[method=post] action='/posts/1001%2F/comments'/> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"&gt;
<html><body>
<p>#[Post:0x1288146 @name="Post_1001"]
#[Post:0x1288146 @name="Post_1001"]
#[Post:0x1288146 @name="Post_1001"]


Comments<br></p>
<form action="/posts/1001/comments" class="new_comment" id="new_comment" method="post">

</form>
</body></html>

./spec/views/posts/show.html.erb_spec.rb:13:
A: 

Does your post-id somehow have a trailing space in it?

Peter McMahan
I don't think so. Isn't the post object being setup in my before(:each) block, which doesn't specify a specific id in the call to mock_model? Besides, I think %2F is a slash...not a space. Hrm...
Eric M.
Oh, you're right about the %2F.
Peter McMahan
A: 

What does your form_for look like in the erb? Rspec can behave oddly for certain routing scenarios that work fine in rails.

What version of rspec are you using (and have you updated recently)?

Why are you spec-ing your views instead of just using cucumber?