1
  1. How do you call a before_filter directly to test it's implementation? Let's say I want to write a spec for ApplicationController that contains a few before filters. What is the standard way to test them? Note, I don't want to test that they've been called - I actually just want to test their implementation once in a single spec.

  2. I like having "render_views" at the top of my controller specs, but when I use stubs, I get all sorts of strange errors as it tries to get the id or other attributes on the stub object. How do you deal with this so that you can make sure your views are correct while using stubs?

I use RSpec.

1 Answer 1

2

Ad 1) Are the proper helpers? Then test them as helpers. If the are methods in you controller then they are private you can test them with the help of send.

require 'spec_helper' 
describe PostsController do
  it "private #scope should be Post.all" do
    @controller.send(:scope).should == Post.all
  end
end

Ad 2) I have render_views as well, saves me some time on testing the views. I don't use stubs but real objects from FactoryGirl or the like. The whole mocking of objects sucks when your objects change and it's a lot of extra work. Factories aren't. Of course, your tests will get slower, but you'll be testing deeper and wider.

Sign up to request clarification or add additional context in comments.

1 Comment

Oops! I meant to say ApplicationController, not the helper. My bad.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.