[rspec-users] getting controller specs to work on edge

Jeff Dean jeff at jefdean.com
Fri Apr 20 03:16:10 EDT 2007


Sorry - I solved it.  I needed to put the do_get line *before* the response
- so this works:

describe "Requesting /users using GET" do
  controller_name :users

  setup do
    @user = mock_model(User)
    User.stub!(:find).and_return(@user)
  end

  def do_get
    get :index
  end

  it "should render index.rhtml" do
    do_get
    response.should render_template('index')
  end

end



On 4/20/07, Jeff Dean <jeff at jefdean.com> wrote:
>
> I'm using edge spec, edge rspec_on_rails, edge rails.  I just switched to
> edge and ran the translator tool and I'm trying to get everything to pass
> again.  One of my issues is getting render back up and working for my
> controller specs, here's an example:
>
> describe "Requesting /users using GET" do
>   controller_name :users
>
>   setup do
>     @user = mock_model(User)
>     User.stub!(:find).and_return(@user)
>   end
>
>   it "should render index.rhtml" do
>     response.should render_template('index')
>     do_get
>   end
> end
>
> When I run that via rake spec:controllers I get:
>
> NoMethodError in 'Requesting /users using GET should render index.rhtml'
> You have a nil object when you didn't expect it!
> The error occurred while evaluating nil.first_render
> .../vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/render_template.rb:12:in
> `matches?'
>
> Originally, after the translator, the "it" section was:
>
>   it "should render index.rhtml" do
>     controller.should render_template('index')
>     do_get
>   end
>
> But that gave me
>
> NoMethodError in 'Requesting /users using GET should render index.rhtml'
> undefined method `rendered_file' for #<UsersController:0x31d93b0>
> .../vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/render_template.rb:12:in
> `matches?'
>
> Can anyone see what I'm doing wrong??
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070420/6a3ea60a/attachment.html 


More information about the rspec-users mailing list