Created
January 24, 2012 02:54
-
-
Save dnagir/1667512 to your computer and use it in GitHub Desktop.
How the simples thing (its gem) makes specs much easier to read
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
# Controller spec using plain old matchers | |
describe "#create" do | |
let(:participation) { stub 'Participation' } | |
let(:params) { {:participation => {}} } | |
before { InviteUser.stub(:into_company_by_params => participation) } | |
context "with success" do | |
before { participation.stub(:valid? => true) } | |
it "should assign participation" do | |
get(:create, params) | |
assigns(:participation).should == participation | |
end | |
it "should should redirect" do | |
get(:create, params).should be_redirect | |
end | |
end | |
context "with failure" do | |
before { participation.stub(:valid? => false) } | |
before { participation.should_receive(:available_developments).and_return devs } | |
let(:devs) { [stub, stub] } | |
it "should assign participation" do | |
get(:create, params) | |
assigns(:participation).should == participation | |
end | |
it "should render template" do | |
get(:create, params).should render_template :new | |
end | |
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
# Controller spec using `its` gem | |
describe "#create" do | |
let(:participation) { stub 'Participation' } | |
let(:params) { {:participation => {}} } | |
before { InviteUser.stub(:into_company_by_params => participation) } | |
subject { get(:create, params); self } | |
context "with success" do | |
before { participation.stub(:valid? => true) } | |
its(:assigns, :participation) { should == participation } | |
its(:response) { should be_redirect } | |
end | |
context "with failure" do | |
before { participation.stub(:valid? => false) } | |
before { participation.should_receive(:available_developments).and_return devs } | |
let(:devs) { [stub, stub] } | |
its(:assigns, :participation) { should == participation } | |
its(:response) { should render_template :new } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For curious ones, the gem to allow this is its.