Last active
August 29, 2015 14:08
-
-
Save paulspencerwilliams/4717c5c28fd017b8ef08 to your computer and use it in GitHub Desktop.
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
require 'rspec/expectations' | |
RSpec::Matchers.define :be_a_created_for do | expected | | |
match do | actual | | |
expect(actual).to have_http_status(:created) | |
expect(actual.headers["Location"]).to eql("http://test.host/websites/2") | |
end | |
failure_message do |actual| | |
"Expected response to be a <created>, but was #{actual.status} | |
Expected Location to be a <was this?>, but was #{actual.headers['Location']}" | |
end | |
end |
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 "POST create" do | |
describe "with valid params" do | |
it "creates a new Website" do | |
expect { | |
post :create, {:website => valid_attributes}, valid_session | |
}.to change(Website, :count).by(1) | |
end | |
it "assigns a newly created website as @website" do | |
post :create, {:website => valid_attributes}, valid_session | |
expect(assigns(:website)).to be_a(Website) | |
expect(assigns(:website)).to be_persisted | |
end | |
it "redirects to the created website" do | |
post :create, {:website => valid_attributes}, valid_session | |
expect(response).to be_a_created_for(Website.last) | |
end | |
end | |
describe "with invalid params" do | |
it "assigns a newly created but unsaved website as @website" do | |
post :create, {:website => invalid_attributes}, valid_session | |
expect(assigns(:website)).to be_a_new(Website) | |
end | |
it "re-renders the 'new' template" do | |
post :create, {:website => invalid_attributes}, valid_session | |
expect(response).to render_template("new") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment