Skip to content

Instantly share code, notes, and snippets.

@helioalb
Created October 8, 2015 12:27
Show Gist options
  • Select an option

  • Save helioalb/1dc3e74189ef758c7100 to your computer and use it in GitHub Desktop.

Select an option

Save helioalb/1dc3e74189ef758c7100 to your computer and use it in GitHub Desktop.
Sugestões para rspec
RSpec.describe UsersController, type: :controller do
describe 'GET #show' do
before
get :show, id: user_id
end
context 'when user exists' do
let(:user_id) { create(:user).id }
it 'return success (200) status code' do
expect(response).to be_success
end
it 'returns the correct user' do
expect(JSON.parse(response.body)['id']).to eq user.id
end
end
context 'when user does not exists' do
let(:user_id) { 'not existent' }
it 'return not found (400) status code' do
expect(response).to be_not_found
end
it 'returns the not found message' do
expect(JSON.parse(response.body)['errors']).to inclue 'User not found'
end
end
end
end
@helioalb
Copy link
Author

Mais uma

  let(:men_customers) do
    10.times.do { |n| create :user, email: "man#{n}@people.com" }
  end

  let(:women_customers) do
    2.times.do { |n| create :user, email: "woman#{n}@people.com" }
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment