Skip to content

Instantly share code, notes, and snippets.

@AVGP
Created April 18, 2012 19:12
Show Gist options
  • Save AVGP/2415849 to your computer and use it in GitHub Desktop.
Save AVGP/2415849 to your computer and use it in GitHub Desktop.
RSpec example
describe "Users" do
describe "Sign up" do
describe "with invalid data" do
it "should not create user" do
lambda do
visit signup_path
fill_in "Name", :with => ""
fill_in "Email", :with => ""
fill_in "Password", :with => ""
fill_in "Confirm password", :with => ""
click_button
response.should render_template('new')
response.should have_selector("div.error")
end.should_not change(User, :count)
end
end
describe "with valid data" do
it "should create a user in the database" do
lambda do
visit signup_path
fill_in "Name", :with => "Tester"
fill_in "Email", :with => "[email protected]"
fill_in "Password", :with => "a" * 9
fill_in "Confirm password", :with => "a" * 9
click_button
response.should render_template('users/show')
response.should have_selector("p.success", :content => 'Welcome')
end.should change(User, :count).by(1)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment