This time I'm actually doing test-driven development, with RSpec, and trying out the new Rails 4.0!
I've been using Michael Hartl's tutorial (ruby.railstutorial.org) as a reference, since my app's functionality is somewhat similar to his. However, I've ran into a few issues so far.
For example, testing in RSpec:
describe "when email is already taken" do
before do
user_same_email = @user.dup
user_same_email.name = "different_name"
user_same_email.save
end
it { should_not be_valid }
end
Running this spec caused a problem, because the 4th line saves user_same_email to the test database, and then fails more specs the next run because of the persisting duplicate email address in the database.
Running "rake test:prepare" seems to fix it temporarily, but running the specs more than once results in a failure. I didn't have this issue when I was using Rails 3.2 on Michael Hartl's tutorial,
I enjoy the fast test times since I can't get Spork to work with Rails 4, so I'm okay with this as long as I find a simple solution.
describe "when email is already taken" do
before do
@user_same_email = @user.dup
@user_same_email.name = "different_name"
@user_same_email.save
end
it { should_not be_valid }
after { @user_same_email.destroy } # Changed to instance variable due to variable scope
end
That works.
Edit: It appears that the version of RSpec I was using (2.13.0) was the problem. I have updated my RSpec to 2.14.0.rc1 and it now works fine; my tests run equally fast and the test database clears between each run as expected.
No comments:
Post a Comment