2009/3/21 Guilherme Machado Cirne <[email protected]>:
> Hi,
>
> I have the following method in a Rails view helper:
>
> def title
> content_for(:title) do
> # some code which generates a title dynamically
> end
> end
>
> How can I spec that the code inside the block returns the correct title?
My preference is to let my view helpers be rendered in my view specs,
and I move the logic that constructs the title onto a presenter. Then
I can say things like this in my view spec:
it "should render the title" do
thing = mock "thing presenter", :title => "foo"
assign[:thing] = thing
render "some.template"
response.should contain("foo")
end
And I can have a presenter spec which verifies the title is built correctly
describe ThingPresenter do
describe '#title' do
it "should return a concatenated title, user name, blah blah blah" do
# ....
end
end
end
There are more ways to accomplish this I know, but I've grown to
become extremely fond of the clean separation between constructing
markup and producing presentation content. It makes things easier to
spec IMO, gives things a good home, and allows me to stop looking at
content for instance variables dynamically generated by Rails.
If interested... http://wiki.github.com/mhs/caching_presenter
--
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users