Je viens de commencer à utiliser BDD avec RSpec/Cucumber/Webrat et Rails et j'ai rencontré de la frustration en essayant d'obtenir ma vue spec à passer. Tout d'abord, je cours Ruby 1.9.1p129 avec Rails 2.3.2, RSpec et RSpec-Rails 1.2.6, Cucumber 0.3.11 et Webrat 0.4.4.Rails, RSpec et Webrat: la sortie attendue correspond à la sortie rendue mais continue d'afficher une erreur dans la spécification de vue
Voici le code correspondant à ma 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 }
vues/backend/messages/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
Voici la partie pertinente de la sortie lorsque je lance 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>
Il me semble que ce have_selector cherche est exactement ce que le modèle génère, mais l'exemple échoue toujours. Je suis très impatient de voir mon erreur (parce que j'ai le sentiment que c'est mon erreur). Toute aide est très appréciée!
Mise à jour: Cela fonctionne si je supprime le bloc. –