I'm going through The RSpec Book, and (specifically around page 333) I encountered a problem. Basically, whenever I use "should have_selector" in a nested form, it silently passes when it SHOULD fail.
I've been copying the code exactly as from the book. Now, there is one major difference - I'm using Capybara while the book is using Webrat. Why? I've had bigger problems with Webrat. In fact, when I switch to Webrat by putting it in the Gemfile, I get this unidentified method error in which has_selector isn't recognized (which is doubly odd because this happens where I call have_selector...)
Anyway, here's the code:
-------new.html.erb_spec.rb-------
require 'spec_helper'
describe "messages/new.html.erb" do
let(:message) do mock_model("Message").as_new_record.as_null_object end
before do assign :message, message end
it "renders a form to create a message" do render rendered.should have_selector("form", :method => "post", :action => messages_path ) do |form| form.should have_selector("input", :type => "submit") # this should be failing right now!!! end end
# this should be failing right now!!! it "renders a text field for the message title" do message.stub(:title => "the title") render rendered.should have_selector("form") do |form| form.should have_selector("input", :type => "submit", :name => "message[title]", :value => "the title" ) end end
# this should be failing right now!!! it "renders a text area for the message text" do message.stub(:text => "the message") render rendered.should have_selector("form") do |form| form.should have_selector("textarea", :name => "message[text]", :content => "the message" ) end end end
-----new.html.erb------
<%= form_for @message do |f| %>
# nothing is in here, so those nested "should have_selector" statements should fail
<% end %>
Thanks in advance!