Last active
December 16, 2015 15:09
-
-
Save blairanderson/5453560 to your computer and use it in GitHub Desktop.
stubs with controller tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context "using OpenStruct to stub" do | |
fake_article = OpenStruct.new(valid?:true) | |
Article.stub(:create).and_return(fake_article) | |
post :create | |
end | |
context "stubbing some shit" do | |
# after you test the before_filter, it can be stubbed for future tests | |
before do | |
controller.stub(:require_login).and_return(true) | |
end | |
Order.stub(:all).and_return([:a1,:a2,]) | |
Order.should_receive(:all).and_return([ ]) | |
expect(response).to redirect_to(article_path) | |
end | |
describe Application controller do | |
describe "#require_login" do | |
it "should work" do | |
#response = ActionDispatch::TestResponse.new | |
#controller.response = response | |
controller.stub(:logged_in?).and_return(false) | |
controller.should_receive(:redirect_to).with(login_path) | |
controller.send(:require_login) | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment