Rails, RSpec, and Webrat: expected output is displayed, but spec errors still occur

I just started using BDD with RSpec / Cucumber / Webrat and Rails, and I came across some frustrations when trying to convey my view specification.

First of all, I run 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 related 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 } 

view / backend / messages / create.html.erb:

 <% form_tag do %> <% end %> 

specification / opinion / backend / messages / 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 seems to me that what the_selector is looking for is exactly what the template generates, but this example still fails. I really hope to see my mistake (because I have the feeling that this is my mistake). Any help is much appreciated!

+4
source share
1 answer

If you want the block to try using rspec-rails routines instead of webrat matches.

 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_tag("form[method=post][action=?]", b_posts_path) do |form| with_tag('input') # ... etc end end end 
+2
source

Source: https://habr.com/ru/post/1286549/


All Articles