Mohamad El-Husseini
2012-Feb-29 04:43 UTC
[rspec-users] Can anyone tell me why this test is failing?
I ran this scenario in the console and it works as expected. But RSpec keeps failing the test and I can''t understand why. describe User do before do @user = User.new(name: "Mickey Mouse", email: "mickey at disney.com", password: "m1ckey", password_confirmation: "m1ckey") end # Password describe "when password is not present" do before { @user.password = @user.password_confirmation = " " } it { should_not be_valid } end end --> expected valid? to return false, got true If I take out the @user.password_confirmation from the assignment, it works: before { @user.password = " " } it { should_not be_valid } But, as I said, using the console I can verify that everything works as expected. Why does adding @password_confirmation break the test? Here''s my user model: class User < ActiveRecord::Base attr_accessible :name, :email, :password, :password_confirmation has_secure_password validates :password, length: { minimum: 6 } end -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120228/d031e148/attachment.html>
Justin Ko
2012-Feb-29 09:18 UTC
[rspec-users] Can anyone tell me why this test is failing?
On Feb 28, 2012, at 9:43 PM, Mohamad El-Husseini wrote:> I ran this scenario in the console and it works as expected. But RSpec keeps failing the test and I can''t understand why. > > describe User do > > before do > @user = User.new(name: "Mickey Mouse", email: "mickey at disney.com", password: "m1ckey", password_confirmation: "m1ckey") > end > > # Password > describe "when password is not present" do > before { @user.password = @user.password_confirmation = " " } > it { should_not be_valid } > end > end > > --> expected valid? to return false, got true > > If I take out the @user.password_confirmation from the assignment, it works: > > before { @user.password = " " } > it { should_not be_valid } > > But, as I said, using the console I can verify that everything works as expected. Why does adding @password_confirmation break the test? > > Here''s my user model: > > class User < ActiveRecord::Base > attr_accessible :name, :email, :password, :password_confirmation > has_secure_password > validates :password, length: { minimum: 6 } > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-usersCan''t reproduce. What versions are you using? Ruby, Rails, RSpec Also, do you have a `subject` set?
Mohamad El-Husseini
2012-Feb-29 12:58 UTC
[rspec-users] Can anyone tell me why this test is failing?
Sorry, after much frustration, I closed the terminal window and restarted everything. The test passed. I have a feeling it might have had something to do with Spork or Guard... sorry for the false alarm! I should restart my terminal more often! On Wednesday, February 29, 2012 6:18:10 AM UTC-3, Justin Ko wrote:> > > On Feb 28, 2012, at 9:43 PM, Mohamad El-Husseini wrote: > > > I ran this scenario in the console and it works as expected. But RSpec > keeps failing the test and I can''t understand why. > > > > describe User do > > > > before do > > @user = User.new(name: "Mickey Mouse", email: "mickey at disney.com", > password: "m1ckey", password_confirmation: "m1ckey") > > end > > > > # Password > > describe "when password is not present" do > > before { @user.password = @user.password_confirmation = " " } > > it { should_not be_valid } > > end > > end > > > > --> expected valid? to return false, got true > > > > If I take out the @user.password_confirmation from the assignment, it > works: > > > > before { @user.password = " " } > > it { should_not be_valid } > > > > But, as I said, using the console I can verify that everything works as > expected. Why does adding @password_confirmation break the test? > > > > Here''s my user model: > > > > class User < ActiveRecord::Base > > attr_accessible :name, :email, :password, :password_confirmation > > has_secure_password > > validates :password, length: { minimum: 6 } > > end > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > Can''t reproduce. What versions are you using? Ruby, Rails, RSpec > > Also, do you have a `subject` set? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120229/d385facc/attachment-0001.html>
Justin Ko
2012-Feb-29 13:10 UTC
[rspec-users] Can anyone tell me why this test is failing?
On Feb 29, 2012, at 5:58 AM, Mohamad El-Husseini wrote:> Sorry, after much frustration, I closed the terminal window and restarted everything. The test passed. I have a feeling it might have had something to do with Spork or Guard... sorry for the false alarm! I should restart my terminal more often! > > On Wednesday, February 29, 2012 6:18:10 AM UTC-3, Justin Ko wrote: > > On Feb 28, 2012, at 9:43 PM, Mohamad El-Husseini wrote: > > I ran this scenario in the console and it works as expected. But RSpec keeps failing the test and I can''t understand why. > > > > describe User do > > > > before do > > @user = User.new(name: "Mickey Mouse", email: "mickey at disney.com", password: "m1ckey", password_confirmation: "m1ckey") > > end > > > > # Password > > describe "when password is not present" do > > before { @user.password = @user.password_confirmation = " " } > > it { should_not be_valid } > > end > > end > > > > --> expected valid? to return false, got true > > > > If I take out the @user.password_confirmation from the assignment, it works: > > > > before { @user.password = " " } > > it { should_not be_valid } > > > > But, as I said, using the console I can verify that everything works as expected. Why does adding @password_confirmation break the test? > > > > Here''s my user model: > > > > class User < ActiveRecord::Base > > attr_accessible :name, :email, :password, :password_confirmation > > has_secure_password > > validates :password, length: { minimum: 6 } > > end > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > Can''t reproduce. What versions are you using? Ruby, Rails, RSpec > > Also, do you have a `subject` set? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-usersThis is why I don''t use spork. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120229/96228890/attachment.html>