Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created September 16, 2015 15:08
Show Gist options
  • Save anonymous/ed7fced52dbde5cd36f9 to your computer and use it in GitHub Desktop.
Save anonymous/ed7fced52dbde5cd36f9 to your computer and use it in GitHub Desktop.
class A
include ::RSpec::Matchers
def foo
expect('1'.to_i).to eq 1
end
end
puts A.new.foo #=>
=begin
If we comment out include ::RSpec::Matchers we get an undefined error for expect.
So ::RSpec::Matchers, somehow, contains expect
And yet ::RSpec::Matchers.methods.include? :expect #=> false
And there's all kinds of weirdness going on here.
I expected this to work to not throw an error:
include ::RSpec::Matchers
expect('1'.to_i).to eq 1
Instead the expect HAS to be inside an instance method of a class otherwise expect is undefined.
Could someone explain? Hopefully when somebody explains how ::RSpec::Matchers doesn't contain 'expect' but
provides 'expect' it will clear the latter questions up.
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment