Created
October 17, 2016 16:53
-
-
Save 8parth/f3a4dce410f12139b33feef008878512 to your computer and use it in GitHub Desktop.
explaining usage for let block in rspec 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
RSpec.describe UsersController, type: :controller do | |
# let can be used as instance variables, instead of @user | |
let(:create_user) { FactoryGirl.create(:user) } | |
let(:new_path){ new_user_path } | |
let(:edit_path){ edit_user_path } | |
# let can be used as parameters that can be shared across examples | |
let(:create_params){ | |
{ | |
name: "NAME", | |
age: "20" | |
} | |
} | |
describe "POST #create" do | |
context "with valid parameters" do | |
before(:each) do | |
post :create, create_params | |
end | |
it { should respond_with(200) } | |
it "should return valid JSON response" do | |
response_body = JSON.parse(response.body) | |
expect(response_body[:data][:name]).to eq(create_params[:name]) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment