Search code examples
ruby-on-railsrspecrspec-rails

ruby on rails rspec command


So as a beginner I am following Michael Hart's ruby on rails 2nd edition tutorial !

when I run command line with the integration test module

rspec test/integration/static_pages_test.rb

it's not showing what Hartl's getting. Instead it's showing this :

/Users/Name/rails_testprojects/protego/test/integration/static_pages_test.rb:1:in `require': no such file to load -- test_helper (LoadError)
    from /Users/Name/rails_testprojects/protego/test/integration/static_pages_test.rb:1:in `<top (required)>'
    from /Users/Name/.rvm/gems/ruby-1.9.2-p320@twitclone/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load'
    from /Users/Name/.rvm/gems/ruby-1.9.2-p320@twitclone/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
    from /Users/Name/.rvm/gems/ruby-1.9.2-p320@twitclone/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
    from /Users/Name/.rvm/gems/ruby-1.9.2-p320@twitclone/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
    from /Users/Name/.rvm/gems/ruby-1.9.2-p320@twitclone/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
    from /Users/Name/.rvm/gems/ruby-1.9.2-p320@twitclone/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
    from /Users/Name/.rvm/gems/ruby-1.9.2-p320@twitclone/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'

Note : In Hartl's tutorial , the integration test is in a different folder called !

bundle exec rspec spec/requests/static_pages_spec.rb

can someone please explain what's going on ? I am a total beginner and have just started following his tutorials !


Solution

  • You say you're following Michael Hartl's Rails Tutorial book, but you really aren't following it; at least not as rigorously as required ;-)

    Rails Tutorial book uses RSpec as the testing framework of choice. In rspec, all the test files are under spec folder, and are called specs.

    Rails by default comes with Test::Unit testing framework, and it places the files under test folder.

    You are mixing both of them and are getting confused.

    I suggest you to stick with what's there in Rails Tutorial book, and rigorously follow the instructions there to get the most out of your time spent in learning rails.