Bugs: Browse | Submit New | Admin

[#15977] undefined method `stub' for nil:NilClass when using mocha outside unit test methods

Date:
2007-11-27 21:42
Priority:
3
Submitted By:
Radosław Bułat (radarek)
Assigned To:
Nobody (None)
Category:
None
State:
Closed
Summary:
undefined method `stub' for nil:NilClass when using mocha outside unit test methods

Detailed description
I have the same issue that is described under http://rubyforge.org/pipermail/mocha-developer/2007-August/000423.html.

Code:

  require 'rubygems'
  require 'mocha'

  some_time = Time.at(0)
  Time.expects(:now).returns(some_time)
  puts Time.now

Running it caused:

  /usr/local/lib/ruby/gems/1.8/gems/mocha-0.5.4/lib/mocha/object.rb:40:
  in `expects': undefined method `stub' for nil:NilClass (NoMethodError)
	from test8.rb:5

My gem version:

$ gem list mocha

*** LOCAL GEMS ***

mocha (0.5.5)


Add A Comment: Notepad

Please login


Followup

Message
Date: 2007-11-29 10:56
Sender: James Mead

I've amended (in revision 198) the misc.rb example as you suggest
to avoid any further confusion. Please close this bug report
if you are happy with this fix. Many thanks.
Date: 2007-11-28 00:10
Sender: Radosław Bułat

I thought that mocha works also outside test methods, but I
see was wrong. My advice is to change examples, because not
all show usage with in framework test context (for example:
http://mocha.rubyforge.org/examples/misc.html). My intention
was to follow with them in irb. Now all is clear for me.
Thanks for response!
Date: 2007-11-27 22:40
Sender: James Mead

Did you see my responses at [1] and particularly [2]? Please
let me know if these don't answer your question. Thanks for your
interest in Mocha.

Cheers, James.
http://blog.floehopper.org

[1] http://rubyforge.org/pipermail/mocha-developer/2007-August/00
0424.html
[2] http://rubyforge.org/pipermail/mocha-developer/2007-August/00
0426.html

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

Field Old Value Date By
status_idOpen2007-11-29 11:42radarek
close_date2007-11-29 11:422007-11-29 11:42radarek