views:

32

answers:

2

I have a PathsHelper that overwrites foo_url and foo_path by processing additional parameters as well as the context from the current url. This is included in ApplicationController.

Right now, I have:

describe ApplicationController do
  describe "#foo_url" do
     ...
  end
  describe "#foo_path" do
     ...
  end
end

I'm wondering whether it's better to do something along the lines of:

describe PathsHelper do
  describe "#foo_url" do
     ...
  end
  describe "#foo_path" do
     ...
  end
end

If so, is there any reasonable way to set some instance variables in the helper test, as there are conditions based on the current url.

+4  A: 

The Controller

Remember in RSpec you are specifying behaviors and making sure those behaviors happen the way you want them to. Those behaviors happen via interaction with your controller. So, write your specs for the controller and make sure you test for the behavior the helper exhibits.

You want to avoid too much poking into the guts of your classes and objects. That's one of the main reasons RSpec came about. People were doing silly tests on the internal state of their classes instead of testing for the desired outcomes.

Mike Bethany
+2  A: 

While RSpec does aim to focus on behaviour, I still spec complex helpers in helper specs. That's why helper specs exist in RSpec in the first place :)

David Chelimsky
Well there ya go, the guy that wrote RSpec has given us the answer ;)
Mike Bethany
David, if I do this, how do I set instance variables inside the helper, as foo_url and foo_path behave differently if an instance variable is set.
Joe Arasin