> it "should send a mail" do
> expect { click_button submit}.to change(Mailer, :count).by(1)
> end
In my opinion, capybara request specs are more for expressing the expectation of
what a user should see...
A user has no idea that clicking a button is going to increase some
database table's record count... So, I think a more useful test would
be on the controller level, which would do something like:
describe MailersController do
describe "#create" do
it "creates a mail record" do
expect { post :create, valid_mailer_params }.to change { Mailer.count
}.by(1)
response.should redirect_to root_path
end
it "requires a valid attributes" do
expect { post :create, invalid_mailer_params }.to_not change {
Mailer.count }
response.should render_template('mailers/new')
end
end
end
and then your request spec might end up just being something more simple
like:
describe "sending some mail" do
it "takes the user back to the home page" do
visit mailers_path
fill_in "Company name", with: "Mailer Company"
fill_in "Contact name", with: "Mailer Contact"
fill_in "Address", with: "Mailer Address"
fill_in "Telephone", with: "123-456-789"
fill_in "Email", with: "[email protected]"
fill_in "Description", with: "something to say"
click_button "Send my Mail"
expect(page.current_path).to eq(root_path)
end
end
Patrick J. Collins
http://collinatorstudios.com
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users