Created
February 9, 2011 05:18
-
-
Save benhamill/817924 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Example | |
def to_yaml | |
already_tested | |
end | |
end | |
class ExampleHolder | |
include Example | |
end | |
describe "Example" do | |
subject { ExampleHolder.new } | |
it "should write to a given file" do | |
subject.should_receive(:already_tested).and_return({ 'foo' => 'bar', 'baz' => 'bom' }) | |
subject.to_yaml | |
end | |
end | |
# $ spec spec/example_spec.rb | |
# F | |
# | |
# Failures: | |
# | |
# 1) Example should write to a given file | |
# Failure/Error: already_tested | |
# NoMethodError: | |
# undefined method `already_tested' for #<ExampleHolder:0x9128c80> | |
# # ./spec/example_spec.rb:3:in `to_yaml' | |
# # ./spec/example_spec.rb:16:in `block (2 levels) in <top (required)>' | |
# | |
# Finished in 0.00098 seconds | |
# 1 example, 1 failure |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Example | |
def needs_testing | |
already_tested | |
end | |
end | |
class ExampleHolder | |
include Example | |
end | |
describe "Example" do | |
subject { ExampleHolder.new } | |
it "should write to a given file" do | |
subject.should_receive(:already_tested).and_return({ 'foo' => 'bar', 'baz' => 'bom' }) | |
subject.needs_testing | |
end | |
end | |
# $ spec spec/example_spec.rb | |
# . | |
# | |
# Finished in 0.00075 seconds | |
# 1 example, 0 failures |
Strange additional info: If I add p subject.methods.sort - Object.methods
in the middle of the example, the fail case prints [:already_tested]
and the pass case prints [:already_tested, :needs_testing]
. Which is totally strange. The fail says it knows about already_tested, but then that it doesn't...
Something with modules and inheritance here, I think, since Object has to_yaml defined.
Of relevance:
$ alias spec
alias spec='bundle exec rspec --color'
It turns out bundle exec
has something to do with it. Investigating further and will post more here when I find it out.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that the only difference is the NAME OF THE METHOD BEING TESTED. lolwut?