![]() | B13.0 Difficulty with Code Breaker example |
|
25 Jan 2010, 18:14
E Asa Bour (1 post) |
I am running into two issues when walking from the Code Breaker example. 1) codebreaker/spec/codebreaker/game_spec.rb:7: undefined method `let’ for Spec::Example::ExampleGroup::Subclass_1::Subclass_1:Class (NoMethodError) I am using the exact game_spec.rb contained within the provided source code. I am using Ubuntu and have confirmed that the proper gems are installed:
actionmailer (2.3.5) For some reason it appears that Spec::Mocks is not available. 2) undefined method `double’ for main:Object (NoMethodError) Test Doubles are also not available and this appears to be a related issue. I even tried to explicitly define rspec. Spec::Runner.configure do |config|
config.mock_with :rspec Any help would be greatly appreciated. Thanks, |
|
26 Jan 2010, 04:37
David Chelimsky (206 posts) |
What version of Ruby? Also, please post the code in the spec. Hard to tell what’s going wrong without seeing it. |
|
02 Mar 2010, 21:30
Jonathan MacDonald (1 post) |
Hi Asa, With respect at least to your first error, I believe you may be trying to use the ‘let’ in the before(:each). |
|
30 Mar 2010, 04:00
Pete Lasko (3 posts) |
I’m also on B 13, and have the same error. However, I’m on Ruby 1.8.7 and Rspec 2. I’ll move on if I can’t get this to work, but I’d like to try and understand what is happening. \#game_spec.rb
require 'spec_helper'
module Codebreaker
describe Game do
describe "#start" do
it "sends a welcome message" do
output = double('output')
game = Game.new(output)
output.should_receive(:puts).with('Welcome to Codebreaker!')
game.start
end
it "prompts for the first guess"
end
end
end
1) Codebreaker::Game #start sends a welcome message
Failure/Error: output = double('output')
undefined method `double' for #<Rspec::Core::ExampleGroup::NestedLevel_1::NestedLevel_1:0x1016f64e8>
# ./spec/codebreaker/game_spec.rb:15
|
|
31 Mar 2010, 12:40
David Chelimsky (206 posts) |
Pete – the error message tells you everything you need to know: “undefined method `double’”. The “double” method was added to rspec-1 but was not forward-ported, yet, to rspec-2. It’s in the rspec-2 codebase now, so it will be part of 2.0.0.beta.5, coming soon. Also, the book has not been updated for rspec-2 yet, so you’re probably best off sticking with rspec-1 until it is. |
|
06 Apr 2010, 01:44
Pete Lasko (3 posts) |
Thanks for the heads up. I’d guessed that it was probably missing in the rspec2 codebase. Excited to see it working soon. I’ll figure out how to get back to version 1 for now. Thanks. |
|
21 Dec 2010, 13:48
George L. Githinji (5 posts) |
Has this method been ported for Rspec-2 now? |
|
21 Dec 2010, 19:00
David Chelimsky (206 posts) |
Yes, George. This thread is from 8 months ago, long before RSpec-2 and the book were released. |
|
23 Dec 2010, 00:12
Victor Daniel Guiomar Martins (2 posts) |
I’m having trouble has well, the as_null_object doesn’t seem to work has expected. The code is this:
And the error for the “prompts for the first guess” is: RSpec::Mocks::MockExpectationError: Double “output” received :puts with unexpected arguments expected: (“Enter guess”) got: (“Welcome Codebreaker!”), (“Make a guess”) Running Rspec 2.3.0 and Ruby 1.9.2 |
|
23 Dec 2010, 01:12
David Chelimsky (206 posts) |
Victor – as_null_object is working fine. Look at the failure message! |
|
23 Dec 2010, 10:14
Victor Daniel Guiomar Martins (2 posts) |
Dumb me, sorry David! Sorry again, and thank for the awesome work! |
|
21 Sep 2012, 12:25
m.v john (1 post) |
Thanks Jonathan MacDonald. John |
| You must be logged in to comment |

