我正在阅读 Michael Hartl 的书。我在第 6.3.3 节。我了解我们正在努力实现的目标。但是,对我来说,其中两个规范似乎在测试同一件事:
来自 user_spec.rb:http ://ruby.railstutorial.org/chapters/modeling-users#code-authenticate_spec
describe "return value of authenticate method" do
before { @user.save }
let(:found_user) { User.find_by_email(@user.email) }
describe "with valid password" do
it { should == found_user.authenticate(@user.password) }
end
describe "with invalid password" do
let(:user_for_invalid_password) { found_user.authenticate("invalid") }
it { should_not == user_for_invalid_password } #1
specify { user_for_invalid_password.should be_false } #2
end
end
如果用户的密码不正确,规范 1 和 2 是否都测试数据库不应该验证用户?这些测试有何不同?