16
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RSpecでスタブを使う場所はbefore(:each)

Posted at

RSpecでスタブを使う場所はbefore(:each)

spec/controllers/articles_controller_spec.rb
before :each do
  time_now = Time.local(2012,1,30,18,0,0) 
  Time.stub!(:now).and_return(time_now)
end

この書き方だと問題なく通るが、

spec/controllers/articles_controller_spec.rb
before :all do
  time_now = Time.local(2012,1,30,18,0,0) 
  Time.stub!(:now).and_return(time_now)
end

とした場合は次のように怒られる。

undefined method `stub!' for Time:Class 
16
17
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?