Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Simple Ruby on Rails Application Testing the Whole App Integration Tests

Cant get a the simplest test I can imagine to run

I'm trying to write my first test using rspec, but I can't figure out the magic words.

The plan is to test that the root page of the website exists. It's not clear what to call it, but after watching the video I think maybe spec/integration/slash_spec.rb is a good name?:

require 'rails_helper'

# test that the web server returns a page when asked for the root
class SlashTest < ActionDispatch::IntegrationTest # maybe SlashTest is a good class name?
  test "That / is served" do
    get "/"
    assert_response :success
  end
end

Running bin/rake spec yields no tests run:

% bin/rake spec
/home/dm/.rvm/rubies/ruby-2.2.1/bin/ruby -I/home/dm/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/lib:/home/dm/.rvm/gems/ruby-2.2.1/gems/rspec-support-3.3.0/lib /home/dm/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
No examples found.


Finished in 0.00137 seconds (files took 2.76 seconds to load)
0 examples, 0 failures

What am I doing wrong?

1 Answer

Raymond Wach
Raymond Wach
7,961 Points

You can see the full command that the rake task is running in the first line of Rake's output. I would copy that and start playing around with it to see if you can get it to see your test file.

I suspect the --pattern option is not correct in your situation. That defines where rspec will look for *_spec.rb files. Instead of letting it find your tests automagically, you can just give it the path to your file on the command line.