On Sun, Jul 10, 2011 at 10:33 AM, Leigh Daniels <[email protected]>wrote:
> Hi All,
>
> I'm starting a Rails 3.1 app. Two tests which involve invalid models are
> failing and I don't understand why. The tests are the stock tests generated
> by the rails rspec generator. I'm new to RSpec so I'm probably missing
> something obvious. I'd appreciate some guidance.
>
> **Leigh
>
> =========
>
> rails g rspec:install
> rake test:prepare
> rake spec
>
> Rake spec produces:
>
> Failures:
>
> 1) JobsController create action should render new template when model is
> invalid
> Failure/Error: response.should render_template(:new)
> Expected block to return true value.
> # ./spec/controllers/jobs_controller_spec.rb:25:in `block (2 levels) in
> <top (required)>'
>
> 2) JobsController update action should render edit template when model is
> invalid
> Failure/Error: response.should render_template(:edit)
> Expected block to return true value.
> # ./spec/controllers/jobs_controller_spec.rb:42:in `block (2 levels) in
> <top (required)>'
>
> Finished in 0.53822 seconds
> 10 examples, 2 failures
>
>
Leigh, you're controller spec appear to be missing a call to the following:
render_views
Thus, you'll need to add this line inside the first describe block of the
jobs_controller_spec.rb.
Good luck,
-Conrad
> Controller specs:
>
> it "create action should render new template when model is invalid" do
> Job.any_instance.stubs(:valid?).returns(false)
> post :create
> response.should render_template(:new)
> end
>
> it "update action should render edit template when model is invalid" do
> Job.any_instance.stubs(:valid?).returns(false)
> put :update, :id => Job.first
> response.should render_template(:edit)
> end
>
> JobsController methods:
>
> def create
> @job = Job.new(params[:job])
> if @job.save
> redirect_to @job, :notice => "Successfully created
> \"#{@job.description.chomp}\"."
> else
> render :action => 'new'
> end
> end
>
> def update
> @job = Job.find(params[:id])
> if @job.update_attributes(params[:job])
> redirect_to @job, :notice => "Successfully updated
> \"#{@job.description.chomp}\"."
> else
> render :action => 'edit'
> end
> end
>
> gem list rspec:
>
> rspec (2.6.0)
> rspec-core (2.6.4, 2.6.3)
> rspec-expectations (2.6.0)
> rspec-mocks (2.6.0)
> rspec-rails (2.6.1, 2.6.0)
>
> Gemfile extract:
>
> gem 'rails', '>= 3.1.0.rc4'
> group :development, :test do
> gem 'turn', :require => false
> gem 'rspec-rails', '>= 2.6.1'
> gem 'cucumber-rails'
> gem 'capybara'
> gem 'database_cleaner'
> end
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.