I want to write rspec test to verify a class method which invokes the included module method by the class name. When I call the module method using the Module name it works fine, but throws NoMethodError when invoked by class name.
module Test
def self.module_mtd
p "test"
end
end
class Burger
include Test
attr_reader :options
def initialize(options={})
@options = options
end
def apply_ketchup
@ketchup = @options[:ketchup]
end
def has_ketchup_on_it?
Burger.module_mtd # Throws NoMethodError
Test.module_mtd #Works fine as expected
@ketchup
end
end
describe Burger do
describe "#apply_ketchup" do
subject { burger }
before { burger.apply_ketchup }
context "with ketchup" do
let(:burger) { Burger.new(:ketchup => true) }
it { should have_ketchup_on_it }
end
context "without ketchup" do
let(:burger) { Burger.new(:ketchup => false) }
it { should_not have_ketchup_on_it }
end
end
end