Want to add rspec to my rails 3 app, what do I need to do?

I updated my GEMFile with:

 group :development, :test do

    gem 'rspec'
    gem 'webrat'
    gem 'rspec-rails'

And ran bundle install.

Now I already have a HomeController, so I manually created this:


I don't have an about page so I started my test off with:

require 'spec_helper'

describe HomeController do

  describe "Get 'about'" do
    it "should be successful" do
      get 'about'
      response.should be_success


Now I did:

rspec spec/

Do I need to update some other files for rspec to work, don't understand this error message.


I changed the if to it, now I'm getting:

file to load -- spec_helper (LoadError)
    from /Users/someuser/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from /Users/someuser/dev/rscs/example.com/spec/controllers/home_controller_spec.rb:1
    from /Users/someuser/.rvm/gems/ruby-1.8.7-p302@rails3/gems/rspec-core-2.2.1/lib/rspec/core/configuration.rb:327:in `load'
    from /Users/someuser/.rvm/gems/ruby-1.8.7-p302@rails3/gems/rspec-core-2.2.1/lib/rspec/core/configuration.rb:327:in `load_spec_files'
    from /Users/someuser/.rvm/gems/ruby-1.8.7-p302@rails3/gems/rspec-core-2.2.1/lib/rspec/core/configuration.rb:327:in `map'
    from /Users/someuser/.rvm/gems/ruby-1.8.7-p302@rails3/gems/rspec-core-2.2.1/lib/rspec/core/configuration.rb:327:in `load_spec_files'
    from /Users/someuser/.rvm/gems/ruby-1.8.7-p302@rails3/gems/rspec-core-2.2.1/lib/rspec/core/command_line.rb:18:in `run'
    from /Users/someuser/.rvm/gems/ruby-1.8.7-p302@rails3/gems/rspec-core-2.2.1/lib/rspec/core/runner.rb:55:in `run_in_process'
    from /Users/someuser/.rvm/gems/ruby-1.8.7-p302@rails3/gems/rspec-core-2.2.1/lib/rspec/core/runner.rb:46:in `run'
    from /Users/someuser/.rvm/gems/ruby-1.8.7-p302@rails3/gems/rspec-core-2.2.1/lib/rspec/core/runner.rb:10:in `autorun'
    from /Users/someuser/.rvm/gems/ruby-1.8.7-p302@rails3/bin/rspec:19


See the top line of the backtrace.

/Users/someuser/dev/rscs/example.com/spec/controllers/home_controller_spec.rb:6: syntax error, unexpected kDO, expecting kTHEN or ':' or '\n' or ';' (SyntaxError)

That error message points to a syntax error in your spec file—namely, on line 6, there is a do where it was not expected. That's where you should check first.

if "should be successful" do

I'm betting you meant that if to be an it ;) it is the RSpec method for defining a particular aspect of the class to test, and it, unlike the if operator, can take a block.

Need Your Help

Working with $routeParams undefined and ngRepeat:dupes error

javascript angularjs

I was trying make $routeParams not undefined, and I don't know what I did but ngRepeat:dupes error has appeared. What I made mistake?