Created
December 12, 2012 10:14
-
-
Save petrjanda/4266598 to your computer and use it in GitHub Desktop.
Test without explicit it descriptions.
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
describe "#update" do | |
subject { response } | |
let(:attributes) { stub('attributes') } | |
def do_put | |
put :update, :id => user.id, :user => attributes, :format => format | |
end | |
def expect_user_update_attributes_and_return(result) | |
User.any_instance.expects(:update_attributes).with(attributes).returns(result) | |
end | |
context "html" do | |
let(:format) { :html } | |
context 'with valid attributes' do | |
before do | |
expect_user_update_attributes_and_return(true) | |
do_put | |
end | |
it { should redirect_to(edit_user_path) } | |
end | |
context 'with invalid attributes' do | |
before do | |
expect_user_update_attributes_and_return(false) | |
do_put | |
end | |
it { should render_template(:edit) } | |
end | |
end | |
context "json" do | |
let(:format) { :json } | |
context 'with valid attributes' do | |
before do | |
expect_user_update_attributes_and_return(true) | |
do_put | |
end | |
it { should be_success } | |
describe 'returned json' do | |
subject { JSON.parse(response.body) } | |
it { subject['id'].should == user.id } | |
it { subject['email'].should == user.email } | |
end | |
end | |
context 'with invalid attributes' do | |
before do | |
expect_user_update_attributes_and_return(false) | |
do_put | |
end | |
it { should be_unprocessable_entity } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment