views:

21

answers:

1

Hi

My main rakefile has some tasks to stop and start selenuim as follows:

require 'selenium/rake/tasks'

Selenium::Rake::RemoteControlStartTask.new do |rc|
  rc.port = 4444
  rc.timeout_in_seconds = 3 * 60
  rc.background = false
  rc.wait_until_up_and_running = true
  rc.additional_args << "-singleWindow"
end

Selenium::Rake::RemoteControlStopTask.new do |rc|
  rc.host = "localhost"
  rc.port = 4444
  rc.timeout_in_seconds = 3 * 60
end

This forces the requirement to have the selenuim gem installed to use rake regardless of the rails environment. Where can I put this code so it will only be loaded when the rails environment is set to test?

Rails 2.3

Cheers

+2  A: 

Are you using Rails 3 or Rails 2?

Rails 3 add a blocks like so:

if Rails.env.test?
  require 'selenium/rake/tasks'

  Selenium::Rake::RemoteControlStartTask.new do |rc|
    rc.port = 4444
    rc.timeout_in_seconds = 3 * 60
    rc.background = false
    rc.wait_until_up_and_running = true
    rc.additional_args << "-singleWindow"
  end

  Selenium::Rake::RemoteControlStopTask.new do |rc|
    rc.host = "localhost"
    rc.port = 4444
    rc.timeout_in_seconds = 3 * 60
  end
end

In Rails 2 (or 3 but it's deprecated) like this:

if RAILS_ENV == "test"
  require 'selenium/rake/tasks'

  Selenium::Rake::RemoteControlStartTask.new do |rc|
    rc.port = 4444
    rc.timeout_in_seconds = 3 * 60
    rc.background = false
    rc.wait_until_up_and_running = true
    rc.additional_args << "-singleWindow"
  end

  Selenium::Rake::RemoteControlStopTask.new do |rc|
    rc.host = "localhost"
    rc.port = 4444
    rc.timeout_in_seconds = 3 * 60
  end
end
Mike Bethany
Sorry added rails version to post, its rails 2.3
Sweet thanks will try that