27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Setting up a testing environment<br />

This will now point to the correct location for your dummy application’s Rakefile. If<br />

you had defined a custom task within this dummy application called email_everyone,<br />

it would be available in your engine as app:email_everyone. This is designed to stop<br />

the conflicts between the application and the engine.<br />

Also in Rakefile, you need to replace the use of Rake::TestTask with the equivalent<br />

for RSpec. Let’s remove these lines from Rakefile now:<br />

require 'rake/testtask'<br />

Rake::TestTask.new(:test) do |t|<br />

t.libs :spec<br />

On the final line here you tell Rake to default to the spec task if there is no task specified.<br />

This means that, rather than running rake spec to run the tests, you can run rake.<br />

The second and final location you need to change the test/dummy reference is in<br />

script/rails at the root of your engine. This contains this line:<br />

load File.expand_path('../../test/dummy/script/rails', __FILE__)<br />

This file would normally load the test/dummy/script/rails file directory, if you hadn’t<br />

already moved it. This file is responsible for loading the subcommands for the rails<br />

command. You need to change this line to make it work again:<br />

load File.expand_path('../../spec/dummy/script/rails', __FILE__)<br />

With these changes complete, your move away from Test::Unit is also complete. Your<br />

next step is going to be installing the RSpec and Capybara gems and setting them up.<br />

With those done, then you can get down to writing some tests.<br />

17.4.2 Installing RSpec and Capybara<br />

To install these gems, you’re not going to add them to your Gemfile, but instead to<br />

forem.gemspec. The established best practice for developing gems is to put the dependencies<br />

inside the gemspec. That way, when people install this engine as a gem using<br />

gem install forem, they’ll get all the normal dependencies installed, and if they install<br />

it using gem install forem --dev, they’ll get all the development dependencies as well.<br />

Directly before the end of the Gem::Specification.new block, you’ll put these two<br />

lines to declare that RSpec and Capybara are development dependencies of your<br />

application:<br />

481

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!