Skip to content

Commit

Permalink
Refactored specs to make more readable as well as removing non essent…
Browse files Browse the repository at this point in the history
…ai specs.
  • Loading branch information
baphled committed Aug 5, 2010
1 parent 2a942aa commit ab13406
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions spec/controllers/steps_controller_spec.rb
Expand Up @@ -7,40 +7,42 @@

describe "GET, new" do

context "is associated to a story" do
context "associated to a story" do
before(:each) do
@story = mock_model(Story).as_null_object
Story.stub(:find).and_return @story
end

it "should find the associated story" do
it "finds the associated story" do
Story.should_receive(:find).with("1").and_return @story
get :new, {:story_id => 1}
end

it "should create a new step associated to the story" do
it "creates a new step associated to the story" do
@story.steps.should_receive(:new).with(:story_ids => ["1"])
get :new, {:story_id => 1}
end
end

context "is not associated to a story" do
it "should create a new story" do
context "not associated to a story" do
it "creates a new story" do
Step.should_receive(:new)
get :new
end
end
end

describe "GET, index" do
it "should have a list of steps" do
it "has a list of steps" do
Step.should_receive(:paginate)
get :index
end

it "should have a list of steps search for" do
Step.should_receive(:search).with('Given')
get :index, {:search_text => 'Given'}
context "searching for a step" do
it "searches for steps" do
Step.should_receive(:search).with('Given')
get :index, {:search_text => 'Given'}
end
end
end

Expand All @@ -49,7 +51,7 @@
Step.stub(:new).and_return @step
end

it "should create a new step" do
it "creates a new step" do
Step.should_receive(:new).with(@step)
post :create, {:step => @step}
end
Expand All @@ -59,17 +61,17 @@
@step.stub(:save).and_return true
end

it "should save the step" do
it "saves the step" do
@step.should_receive(:save).and_return true
post :create
end

it "should display a flash[:notice] message" do
it "displays a flash notice message" do
post :create
flash[:notice].should contain "Step: #{@step.title}, was created"
flash[:notice].should_not be_empty
end

it "should save the step" do
it "is saved" do
post :create
response.should be_success
end
Expand All @@ -80,20 +82,20 @@
@step.stub(:save).and_return false
end

it "should not save the step" do
it "is not saved" do
@step.should_receive(:save).and_return false
post :create
end

it "should render the new form" do
it "renders the new form" do
post :create
response.should render_template :new
end
end
end

describe "GET, edit" do
it "should find the step" do
it "finds the step" do
Step.stub(:find).and_return @step
Step.should_receive(:find)
get :edit
Expand All @@ -105,22 +107,22 @@
Step.stub(:find).and_return @step
end

context "successfully updates" do
context "successfully updates" do
before(:each) do
@step.stub(:update_attributes).and_return true
end

it "should update the step" do
it "is updated" do
@step.should_receive(:update_attributes).and_return true
put :update, {:step => @step}
end

it "should display a flash[:notice] message" do
it "displays a flash notice message" do
put :update, {:step => @step}
flash[:notice].should contain "Step: #{@step.title} was updated"
flash[:notice].should_not be_empty
end

it "should save the step" do
it "is saved" do
put :update, {:step => @step}
response.should be_success
end
Expand All @@ -132,12 +134,12 @@
@step.stub(:update_attributes).and_return false
end

it "should display a flash[:error] message" do
it "displays a flash error message" do
put :update, {:step => @step}
flash[:error].should contain "Step: #{@step.title} was not updated"
flash[:error].should_not be_empty
end

it "should render the edit form" do
it "renders the edit form" do
put :update, {:step => @step}
response.should render_template :edit
end
Expand All @@ -148,18 +150,19 @@
before(:each) do
Step.stub(:find).and_return @step
end
it "should find the step" do

it "finds the step" do
Step.should_receive(:find).and_return @step
delete :destroy
end

context "found step" do
it "should destroy the step" do
it "destroys the step" do
@step.should_receive(:destroy).and_return true
delete :destroy
end

it "should redirect to the steps path" do
it "redirects to the steps" do
delete :destroy
response.should redirect_to steps_path
end
Expand Down

0 comments on commit ab13406

Please sign in to comment.