Created
December 21, 2010 13:44
-
-
Save rummelonp/749942 to your computer and use it in GitHub Desktop.
Ruby on Rails3でRSpecを使ったコントローラのテストのコード
This file contains hidden or 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
require 'spec_helper' | |
describe IndexController do | |
describe 'GET "popular"' do | |
context :html, :response do | |
before { get :popular } | |
subject { response } | |
it { should be_success } | |
end | |
context :atom, :response do | |
before { get :popular, format: :atom } | |
subject { response } | |
it { should be_success } | |
end | |
end | |
describe 'POST "find" with empty url' do | |
context 'without XMLHttpRequest' do | |
before { post :find, url: '' } | |
describe :response do | |
subject { response } | |
it { should be_redirect } | |
describe :redirect_to do | |
subject { URI.parse(response.redirect_url).request_uri } | |
it { should == '/' } | |
end | |
end | |
describe :flash, :notice do | |
subject { request.session['flash'][:notice] } | |
it do | |
should == 'Sorry, the user could not find because of an error.' | |
end | |
end | |
end | |
context 'with XMLHttpRequest' do | |
before { xhr :post, :find, url: '' } | |
describe :response, :body do | |
subject { response.body } | |
it do | |
text = 'Sorry, the user id could not find because of an error.' | |
javascript = "alert('#{text}')" | |
should == javascript | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment