On Sep 18, 2010, at 7:01 AM, Brennon Bortz wrote:
> I'm testing a view that renders a form to edit an object. I'd like to test
> that the form correctly populates the form with the object's attributes'
> current values. I tried several variations on mock_model and stub_model in
> order to maintain view/model separation--for instance:
>
> require "spec_helper"
>
> describe "informational_widget_frameworks/edit.html.erb" do
> describe "rendered items" do
> before(:each) do
> @iwf = mock_model(InformationalWidgetFramework,
> :heading => "IWF Heading",
> ).as_null_object
> assign(:informational_widget_framework, @iwf)
> render
> end
>
> it "should show 'IWF Heading'" do
> rendered.should include("IWF Heading")
> end
> end
> end
>
> However, when the view is rendered, the value for the text_field bound to
> @informational_widget_framework.heading is populated with
> "InformationalWidgetFramework_1025". I've tried changing the example to:
>
> it "should show 'IWF Heading'" do
> @iwf.should_receive(:heading).and_return("IWF Heading")
> rendered.should include("IWF Heading")
> end
>
> But, this gives the same results. Using stub_model similarly doesn't
> populate the form fields with anything at all. The only way I can get these
> examples to pass is by using the following for my before block:
>
> before(:each) do
> @iwf = InformationalWidgetFramework.create(
> :heading => "IWF Heading",
> )
>
> assign(:informational_widget_framework, @iwf)
> render
> end
>
> I'm clearly missing something here...can someone clue me in?
What is the view using to render this field? Also, what versions? There was an
as_null_object + rails 3 bug in beta.20 that got fixed in beta.22.
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users