Vote count:
0
I am learning ruby on rails and mongoDB (mongomapper), and I followed Michael Hartl's tutorial, and encountered a problem. Problem is somewhere in test for authentication of password. When I use console and try authentication it works like a charm, but when running test same test of authentication passes first couple of times and then suddenly fails telling me that password in db and variable doesn't match. Here is the code of tests and message of a test.
spec/models/special_case.rb
require 'spec_helper'
require 'pry-debugger'
describe User do
before do
@user = build(:user)
end
subject { @user }
it { should respond_to(:authenticate) }
it { should be_valid }
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 eq found_user.authenticate(@user.password) }
end
describe "with invalid password" do
let(:user_for_invalid_password) { found_user.authenticate("invalid") }
it { should_not eq user_for_invalid_password }
specify { expect(user_for_invalid_password).to be_false }
end
end
end
and here is the error code
bojan@bojan-300E4C-300E5C-300E7C:~/rubyprojects/sample_app$ bundle exec rspec spec/special_case.rb
[DEPRECATION] :index option when defining key "email" is deprecated. Put indexes in `db/indexes.rb`
....F
Failures:
1) User return value of authenticate method with valid password
Failure/Error: it { should eq found_user.authenticate(@user.password) }
expected: #<User _id: BSON::ObjectId('53b6b0f6ac04d82c8e000003'), created_at: Fri, 04 Jul 2014 13:49:42 UTC +00:00, email: "boja00@yahoo.com", name: "Bojan Drljaca", password_digest: "$2a$04$Os57kzr4a/1.5Sf5KG5Ib.MV8xThCY0Tok8SiRVC/9b6vK8kiRFTi", updated_at: Fri, 04 Jul 2014 13:49:42 UTC +00:00>
got: #<User _id: BSON::ObjectId('53b6b0f6ac04d82c8e000005'), email: "boja00@yahoo.com", name: "Bojan Drljaca", password_digest: "$2a$04$WGbfIKjDGvK/0nGPaAZXyuiH/z86MVIe0r6TWlQ72mIQw4XmRuR1m">
(compared using ==)
Diff:
@@ -1,2 +1,2 @@
-#<User _id: BSON::ObjectId('53b6b0f6ac04d82c8e000003'), created_at: Fri, 04 Jul 2014 13:49:42 UTC +00:00, email: "boja00@yahoo.com", name: "Bojan Drljaca", password_digest: "$2a$04$Os57kzr4a/1.5Sf5KG5Ib.MV8xThCY0Tok8SiRVC/9b6vK8kiRFTi", updated_at: Fri, 04 Jul 2014 13:49:42 UTC +00:00>
+#<User _id: BSON::ObjectId('53b6b0f6ac04d82c8e000005'), email: "boja00@yahoo.com", name: "Bojan Drljaca", password_digest: "$2a$04$WGbfIKjDGvK/0nGPaAZXyuiH/z86MVIe0r6TWlQ72mIQw4XmRuR1m">
# ./spec/special_case.rb:20:in `block (4 levels) in <top (required)>'
Finished in 0.10159 seconds
5 examples, 1 failure
Failed examples:
rspec ./spec/special_case.rb:20 # User return value of authenticate method with valid password
Randomized with seed 5909
Test sometimes pass, and suddenly just fails and tells me that password is different (look at hash).
asked 28 secs ago
Aucun commentaire:
Enregistrer un commentaire