Rails, RSpec and Webrat: Expected output matches rendered output but still getting error in view spe
- by Anthony Burns
Hello all,
I've just gotten started using BDD with RSpec/Cucumber/Webrat and Rails and I've run into some frustration trying to get my view spec to pass.
First of all, I am running Ruby 1.9.1p129 with Rails 2.3.2, RSpec and RSpec-Rails 1.2.6, Cucumber 0.3.11, and Webrat 0.4.4.
Here is the code relevant to my question
config/routes.rb:
map.b_posts 'backend/posts',
:controller => 'backend/posts',
:action => 'backend_index',
:conditions => { :method => :get }
map.connect 'backend/posts',
:controller => 'backend/posts',
:action => 'create',
:conditions => { :method => :post }
views/backend/posts/create.html.erb:
<% form_tag do %>
<% end %>
*spec/views/backend/posts/create.html.erb_spec.rb:*
describe "backend/posts/create.html.erb" do
it "should render a form to create a post" do
render "backend/posts/create.html.erb"
response.should have_selector("form", :method => 'post', :action => b_posts_path) do |form|
# Nothing here yet.
end
end
end
Here is the relevant part of the output when I run script/spec:
'backend/posts/create.html.erb should render a form to create a post' FAILED
expected following output to contain a <form method='post' action='/backend/posts'/> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><form action="/backend/posts" method="post">
</form></body></html>
It would appear to me that what have_selector is looking for is exactly what the template generates, yet the example still fails. I am very much looking forward to seeing my error (because I have a feeling it is my error). Any help is much appreciated!