Steve Downey wrote:
I have specs that ran fine in Rails 2.02/RSpec 1.13 that are failing
on Rails 2.1/RSpec 1.14.
There is one problem and one issue:
problem: sometimes (but not always) I get a NoMethodError referencing
a has_many association
issue: in helper specs, instance variables don't get set unless the
HelperModule is included. Using the preferred helper.<method> I can't
seem to find a way to check that an instance variable is set:
I have several specs that used to look like:
it "page_title should assign @browser_title" do
page_title("foo")
@browser_title.should == "foo"
end
Now changed to:
it "page_title should assign @browser_title" do
helper.page_title("foo")
helper.assigns[:browser_title].should == "foo"
# also tried: assigns[:browser_title].should == "foo"
end
The output is:
expected: "foo",
got: nil (using ==)
Any help appreciated.
------------------------------------------------------------------------
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
Steve,
You are basically testing state here... With that said you can get
around this a number of ways. You can forgoe the suggested way of using
helper and just include the module directly. You can then verify that
your expectation of that variable has been set. Like so:
include YourHelper
it "page_title should assign @browser_title" do
page_title("foo")
@browser_title.should == "foo"
end
You could also reach in and pull the variable out of the helper:
it "page_title should assign @browser_title" do
helper.page_title("foo")
helper.instance_variable_get("@browser_title").should == "foo"
end
This way smells bad. In fact, both ways send off warning signals.
Depending on what you are doing this may be needed though, so I hope one
of these ways works for you.
-Ben
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users