Skip to content

Instantly share code, notes, and snippets.

@petrjanda
Created December 12, 2012 10:14
Show Gist options
  • Save petrjanda/4266598 to your computer and use it in GitHub Desktop.
Save petrjanda/4266598 to your computer and use it in GitHub Desktop.
Test without explicit it descriptions.
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