Reputation: 13
I have some private methods in my rails models. I want to spec it out seperately (use rspec).
I do something like this
class TestModelA < ModelA
def public_wrapper_method_A
private_method_A_from_ModelA
end
end
and I write specs for TestModelA#public_wrapper_method_A
I think there is good case for writing specs for private methods.
What is the best way of writing tests for these private methods.
what do you guys think ? pros/cons?
Upvotes: 0
Views: 118
Reputation: 2495
I usually set aside a context
group for private methods and then setup a describes
block for each method. Within the block I define a helper method to call the private method and then the it
blocks use the call_xxx
method to get to the private method.
context "private methods" do
describe "#some_private_method" do
def call_some_private_method
some_obj.send(:some_private_method)
end
it "should return 'something'" do
call_some_private_method.should == 'something'
end
end
end
Upvotes: 1