After including a module in spec_helper
, I am running Minitest spec for a class inside that module and get this error:
test_0001_must be true for option name(MyGem::OptionParser::option?):
NoMethodError: undefined method `option?' for OptionParser:Class
I'm testing lib/options/options.rb:
module MyGem
class OptionParser
def self.option?(arg)
arg =~ /^-{1,2}\w+$/
end
end
end
With spec/options_spec.rb:
describe OptionParser do
describe "option?" do
it "must be true for option name" do
OptionParser.option?('--nocolor').must_equal true
end
end
end
Running the test with MyGem::OptionParser
instead of just OptionParser
doesn't cause errors. But similar test on lib/script.rb
runs without errors without MyGem::
prefix.
My file structure:
gem/
|-lib/
| |-options/
| | |-options.rb
| |-script.rb
|-spec/
| |-script_spec.rb
| |-options_spec.rb
| |-spec_helper.rb
|-Rakefile
I include MyGem
in spec_helper
. What have I got wrong?