[rspec-users] Extending assigns in controller specs?
Scott Taylor
mailing_lists at railsnewbie.com
Thu Apr 5 15:10:57 EDT 2007
One method would be to:
1. figure out the class
2. reopen the class,
3. alias the method,
4. use your method if multiple keys are given, use the old aliased
method if not.
Don't know if assigns might have some metaclass trickery, though.
Post what you find. I'd be interested.
As for spec'ing it out, first:
require File.dirname(__FILE__) + "/..."
class MyController < ActionController
def single_var
@var = "var"
end
def multi_var
@var1 = 1
@var2 = 2
end
end
describe "MyController's single_var" do
controller_name :my_controller
setup do
get :single_var
end
it "should assign one variable" do
assign[:var].should == "var"
end
end
describe "MyController's multi_var" do
...
it "should assign multi variables" do
assign[:var1, :var2].should == [1, 2]
end
end
Obviously you can use more descriptive names than I have here. But I
hope you can see where I'm going with this.
Scott
On Apr 5, 2007, at 8:55 AM, Chris Hoffman wrote:
> Hello,
> I am interested in enhancing assigns in controller specs to do
> things like the following
>
> assigns[:key1, :key2, :key3] #=> vals for keys
>
> Is there away to "break open" this construction to overload the :[]
> operator?
>
> Thanks.
>
> -Chris
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
More information about the rspec-users
mailing list