[rspec-users] Private method in custom module

Phillip Koebbe phillipkoebbe at gmail.com
Thu Dec 31 13:54:34 EST 2009


I have a module of custom examples, such as

module ControllerHelperMethods
	module MyExampleGroupMethods
		def should_set_the_body_id(body_id)
			it "should set the body id to '#{body_id}'" do
				assigns[:body_id].should == body_id
			end
		end
	end

	def self.included(receiver)
		receiver.extend MyExampleGroupMethods
	end
end

and in spec_helper:

Spec::Runner.configure do |config|
	config.include(ControllerHelperMethods, :type => :controllers)
end

I have duplicate code in two of my custom examples, so I want to
refactor it to a private method, but I can't seem to get the private
method to work. I have tried the most obvious way (private keyword
followed by the method), and also a couple of more clever approaches
that involved doing an instance_eval in self.included.

First, should I be able to call private methods in my custom examples?
If so, how.

Peace.
Phillip


More information about the rspec-users mailing list