Skip to content

Instantly share code, notes, and snippets.

@txus
Created June 16, 2010 19:14
Show Gist options
  • Save txus/441129 to your computer and use it in GitHub Desktop.
Save txus/441129 to your computer and use it in GitHub Desktop.
# in customers_controller.rb
def CustomersController < ApplicationController
before_filter :load_languages, :only => :new
def new
...
end
protected
def load_languages
@languages = LANGUAGES
end
end
# in customers_controller_spec.rb
# FAILING
# this satisfies the controller.should_receive expectation
# but assigns[:languages] is then nil
describe CustomersController do
context "when creating a new customer" do
it "should load languages through a before_filter" do
controller.should_receive(:load_languages).exactly(1).times
get :new
assigns[:languages].should eql(LANGUAGES)
end
end
end
# PASSING
# Moving the controller.should_receive expectation to another example makes all green
describe CustomersController do
context "when creating a new customer" do
it "should call the before_filter" do
controller.should_receive(:load_languages).exactly(1).times
get :new
end
it "should load languages thanks to the before_filter" do
get :new
assigns[:languages].should eql(LANGUAGES)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment