我在一个遗留项目中有一个类,如下所示:
class UserObserver < ActiveRecord::Observer
def after_create(user)
unless Rails.env == "development" # don't spam users when running legacy migrations
begin
UserMailer.welcome(user).deliver
subscribe_user_to_new_account_mailinglist user
rescue
# THE FOLLOWING LINE IS THE ONE THAT BOTHERS ME
puts "User##{user.id} - Signed up using an invalid email address."
end
end
end
end
如您所见,那里puts
有。当我运行我们的测试套件时,我得到如下输出:
be rspec spec/models/user_spec.rb
User#1 - Signed up using an invalid email address.
...User#1 - Signed up using an invalid email address.
..User#1 - Signed up using an invalid email address.
.User#1 - Signed up using an invalid email address.
.User#1 - Signed up using an invalid email address.
.User#1 - Signed up using an invalid email address.
.User#1 - Signed up using an invalid email address.
.User#1 - Signed up using an invalid email address.
.User#1 - Signed up using an invalid email address.
.User#1 - Signed up using an invalid email address.
.User#1 - Signed up using an invalid email address.
.User#1 - Signed up using an invalid email address.
.User#1 - Signed up using an invalid email address.
.User#1 - Signed up using an invalid email address.
.User#1 - Signed up using an invalid email address.
.
Finished in 12.19 seconds
18 examples, 0 failures
我不喜欢额外的混乱。好像我应该只看到绿点。
在那条线上而不是puts
?