0

I'm a newbie in ruby/rails, currently doing the railstutorial book as a part of a university course. I'm using ubuntu 11.04, ruby 1.9.2p290, and Rails 3.0.9, watchr (0.7), rspec (2.6.0), rspec-formatter-webkit (2.1.3) and spork (0.9.0.rc).

On github I came across this gem, and I thought it would be very nice to use it. So basically what I'm trying to achieve is continuous automated testing with notifications if finished, and also to generate the nice html output out of it.

So what I tried is that I wrote this watchr script:

require 'nokogiri'
require 'open-uri'

watch("spec/.*/*_spec.rb") do |match|
  run_spec match[0]
end

watch("app/(.*/.*).rb") do |match|
  run_spec %{spec/#{match[1]}_spec.rb}
end

def run_spec(file)
  unless File.exist?(file)
    puts "#{file} does not exist"
    return
  end

puts "Running #{file}"
result = `rspec -r rspec/core/formatters/webkit -f RSpec::Core::Formatters::WebKit #{file}`
File.open('out.html', 'w') do |f|
  f.puts result
end
notify(result)
puts "DONE"
end

def send_notify title, msg, img, pri='low', time=5000
  `notify-send -i #{img} -u #{pri} -t #{time} '#{msg}'`
end

def notify(result)
  output = result
  doc = Nokogiri::HTML(result)
  doc.xpath('//div[@id = "summary"]').each do |node|
    output = node.text.split.join(" ")
  end
  folder = "~/Pictures/autotest/"
  if output =~ /([123456789]|[\d]{2,})\sfailed/
    send_notify "FAIL:", "#{output}", folder+"rails_fail.png", 'critical', 20000
  elsif output =~ /[1-9]\d*\spending?/
    send_notify "PENDING:", "#{output}", folder+"rails_pending.png", 'normal', 15000
  else
    send_notify "PASS:", "#{output}", folder+"rails_ok.png"
  end
end

handling the notifications, and generating the output while testing.

If I run this with watchr, everything is nice and working, however the tests are taking a long time of course.

The problem comes in here: if I try to use spork, to speed the tests up, I get a bunch of errors, starting with a LoadError:

Exception encountered: #<LoadError: no such file to load --  rspec/core/formatters/webkit> 
backtrace:
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in `require'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in `block in require'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in `block in load_dependency'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:596:in `new_constants_in'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in `load_dependency'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in `require'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:247:in `block in requires='
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:247:in `map'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:247:in `requires='
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration_options.rb:21:in `block in configure'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration_options.rb:20:in `each'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration_options.rb:20:in `configure'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:17:in `run'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/monkey/spork/test_framework/rspec.rb:5:in `run_tests'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/run_strategy/forking.rb:13:in `block in run'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/forker.rb:21:in `block in initialize'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/forker.rb:18:in `fork'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/forker.rb:18:in `initialize'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/run_strategy/forking.rb:9:in `new'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/run_strategy/forking.rb:9:in `run'
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc/lib/spork/server.rb:47:in `run'
/usr/local/ruby/lib/ruby/1.9.1/drb/drb.rb:1558:in `perform_without_block'
/usr/local/ruby/lib/ruby/1.9.1/drb/drb.rb:1518:in `perform'
/usr/local/ruby/lib/ruby/1.9.1/drb/drb.rb:1592:in `block (2 levels) in main_loop'
/usr/local/ruby/lib/ruby/1.9.1/drb/drb.rb:1588:in `loop'
/usr/local/ruby/lib/ruby/1.9.1/drb/drb.rb:1588:in `block in main_loop'

which of course don't really say anything to me, being a total newbie.

Is there a way to overcome this (or of course produce result in any other way)?

Any help is greatly appreciated :)

tpv
  • 153
  • 9
  • When you were installing these gems, did you do it incrementally, making sure each of them worked as you intended? I ask because signs are pointing toward rspec-formatter-webkit. Were there any special installation instructions for this gem in particular? – Tass Oct 10 '11 at 13:23
  • I did install them incrementally, and all seemed to work correctly. No specific instructions for the rsepc-formatter gem, just gem install. It can be used conveniently with textmate, but I don't have that, so I wrote a letter to the creator of the gem, and he replied that I can use it the following way:rspec -r rspec/core/formatters/webkit -f RSpec::Core::Formatters::WebKit _file_ – tpv Oct 10 '11 at 15:03
  • @Tass: If it works from the command-line, and works from watchr, what makes you say that "signs are pointing toward rspec-formatter-webkit"? What signs are those? – Michael Granger Oct 10 '11 at 20:26

1 Answers1

0

You might have more luck running the RSpec runner directly rather than shelling out, e.g.,

require 'rspec/core'
require 'rspec/core/formatters/webkit'

# ...then in #run_spec
puts "Running #{file}"
File.open( 'out.html', 'w' ) do |f|
  argv = [ '-f', 'RSpec::Core::Formatters::WebKit', file ]
  RSpec::Core::Runner.run( argv, f )
end
notify(result)
puts "DONE"

The ActiveSupport monkey(freedom)-patched 'Kernel.require' seems to be the thing that's different in the three scenarios you mentioned.

If you figure out why ActiveSupport can't find the library, I'd be happy to try to work around it in the WebKit formatter.

Michael Granger
  • 1,358
  • 9
  • 14