5

I have installed growl + rspec + autotest on my windows 7 machine. From the command prompt, when I type 'rspec spec/' it doesn't work. The tests will only run if I use 'rake spec/' + 'autotest'.

Also, I am running these tests: http://railstutorial.org/chapters/static-pages#code:default_pages_controller_spec (i.e. very, very trivial) and they are taking 8.11 seconds.

They also fail when I run them - even though they don't in the example. I have done everything the tutorial told me, the problem is the tutorial doesn't go too deep into installing rspec on a Windows machine. It gives a link, but even then you have to kinda piece the instructions together.

The errors I get are 'Failure/Error: Unable to find C to read failed line [31mundefined methord get' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x48336c0>'

The second error is very similar to that.

I have also installed Growl correctly, because I get a notification that there were two failures.

Can anyone help me?

marcamillion
  • 32,933
  • 55
  • 189
  • 380
  • marcamillion, when you get a chance, could you comment with the exact versions of ruby, rails, rspec and autotest that you see this problem with? I'm going to try to reproduce it with the latest stable of each of these, but just in case I'd like to know your versions. – carols10cents Jan 13 '11 at 00:51

3 Answers3

3

I did a little googling, and according to this thread on the rspec ruby forum and this closed rspec-rails issue, this is an issue with rspec-rails that has been fixed.

I am running Ruby 1.9.2p136 on Windows 7 using rails 3.0.3.

This is what my Gemfile looked like, which shows the versions of rspec and rspec-rails that I was using:

source 'http://rubygems.org'

gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'

group :development do
  gem 'rspec-rails', '2.4.1'
end

group :test do
  gem 'rspec', '2.4.0'
  gem 'webrat', '0.7.1'
end

I say "lookED like" because when I tried to run the rspec rails generator, this is what I got:

C:\Ruby\sample_app>rails generate rspec:install
  create  .rspec
  create  spec
  create  spec/spec_helper.rb
Could not find "autotest" in any of your source paths. Your current source paths
 are:
C:/Ruby/sample_app/lib/templates/rspec/install
C:/Ruby/192-stackoverflow/lib/ruby/gems/1.9.1/gems/rspec-rails-2.3.0/lib/generators/rspec/install/templates

So then I added autotest to my Gemfile (and did bundle install again), then tried rails generate rspec:install again and it worked with no errors. So this is what my Gemfile looks like now:

source 'http://rubygems.org'

gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'

group :development do
  gem 'autotest'
  gem 'rspec-rails', '2.4.1'
end

group :test do
  gem 'rspec', '2.4.0'
  gem 'webrat', '0.7.1'
end

And the version of autotest that this installs is 4.4.6:

C:\Ruby\sample_app>bundle show autotest
C:/Ruby/192-stackoverflow/lib/ruby/gems/1.9.1/gems/autotest-4.4.6

I then created the controller as instructed in the tutorial:

$ rails generate controller Pages home contact

And I was able to run both "bundle exec autotest" and "rspec spec/" without getting the error you are seeing:

C:\Ruby\sample_app>bundle exec autotest
loading autotest/rspec2
bundle exec C:\Ruby\192-stackoverflow\bin\ruby -S C:/Ruby/192-stackoverflow/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/bin/rspec --tty 'C:/Ruby/sample_app/spec/controllers/pages_controller_spec.rb'
..

Finished in 23.04 seconds
2 examples, 0 failures
# I killed autotest with CTRL-c at this point
Interrupt a second time to quit
Terminate batch job (Y/N)? y
Terminate batch job (Y/N)? y


C:\Ruby\sample_app>rspec spec/
..

Finished in 23.11 seconds
2 examples, 0 failures

I also continued on with the tutorial, writing specs for the About page, while autotest was running and it was running on my changes without any problems.

So please try:

  1. Updating your Gemspec to look similar to my 2nd one posted here
  2. Running 'bundle install'
  3. Running 'bundle exec autotest'

and let me know if that works. I will be checking back!

carols10cents
  • 6,943
  • 7
  • 39
  • 56
2

I thought that this might help those who might be having trouble now that all the gems have been updated quite a bit (especially for those using Ruby on Rails 3 tutorial):

I was able to get this working using the latest versions of all gems:

My Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.6'
gem 'jquery-rails'

gem 'sqlite3', :group => [:development, :test]
gem 'pg', :group => :production #This is so Heroku will work

group :development do
  gem 'rspec-rails'
end

group :test do
  gem 'rspec'
  gem 'webrat'
  gem 'spork-rails'  #Use this is only if you want to use spork
end

Make sure you clean up rspec if you've already got an older version (by using the Ruby on Rails 3 tutorial, for example): https://stackoverflow.com/a/4433217/911133

To use autotest follow the directions here: https://github.com/svoop/autotest-growl

Note that installing growl-for-windows is part of that deal and snarl is not needed: http://www.growlforwindows.com/

Your .autotest file can be in one of two places

1) your HOME directory, which is (example):

C:\users\joeblow\.autotest

2) the rails application root (this will then operate for that app only)

my .autotest file looks like this:

require 'autotest/growl'
require 'autotest/restart'
require 'autotest/timestamp'

Autotest.add_hook :initialize do |autotest|
  autotest.add_mapping(%r%^spec/(requrests)/.*rb$%) do
|filename, _|
filename
end
end

Autotest::Growl::clear_terminal = false

Make sure you've done a 'bundle install'

Then run Growl for windows (start menu or start on windows boot)

run autotest in the command line and you should be good to go!

c:\users\joeblow\workspace\Rails\MyRailsProject> autotest
Community
  • 1
  • 1
1

I've not found a permanent fix that works yet, but apparently it boils down to a path issue - something is munging the windows path and it breaks. However, there's a work around:

Within your describe, before the 'get' call, put this:

include RSpec::Rails::ControllerExampleGroup

Here's sample code using a generated Rails spec for a controller. Note that it's at the beginning of the scope:

require 'spec_helper'

describe PagesController do
  include RSpec::Rails::ControllerExampleGroup

  describe "GET 'home'" do
    it "should be successful" do
      get 'home'
      response.should be_success
    end
  end

  describe "GET 'contact'" do
    it "should be successful" do
      get 'contact'
      response.should be_success
    end
  end

end

There's a fix I've seen that suggests a change to spec_helper (in the Rails case), but I couldn't get it to work.

EDIT: A bit more research reveals this is a problem with autospec - this work around will work if you're just using rspec, but will not work with autotest. I've not been able to find a solution for this, however.

tsalaroth
  • 112
  • 9