[rspec-users] Running Cucumber with a Rails Rake task

Zach Dennis zach.dennis at gmail.com
Sat Oct 18 16:53:44 EDT 2008


To run all features you can run:

  rake features

To run specific features you can do something like:

  script/cucumber --require features/steps features/path/to/my.feature

If you want to run a particular scenario find out the line number of
the first Given and run:

  script/cucumber --line 41 --require features/steps features/path/to/my.feature

Zach


On Sat, Oct 18, 2008 at 4:33 PM, Ben Emson <lists at ruby-forum.com> wrote:
> Hi All
>
> I've just started experimenting with Cucumber and its great.
> However I wasn't quite sure how I should integrate it into my Rails
> application.
>
> What I would like to do is set my Rails app up so that I can run a
> Cucumber rake task using the standard Rails Rake system.
>
> I've looked through the example source and understand how the Calculator
> demo Rake file works, but I'm not sure I've set it up correctly in my
> Rails app.
>
> This is what I've done.
>
> Created a new file:
> my_app/lib/tasks/cucumber.rake
>
> I experimented trying to use the following Cucumber rake task but could
> not get my steps to load my model code as I was hoping that I could tell
> Cucumber what my Rails lib files were:
>
> Cucumber::Rake::Task.new do |t|
>  t.libs = ["#{RAILS_ROOT}/config/environment"] # This doesn't seem to
> work
>  Dir.chdir("#{RAILS_ROOT}/stories/")
>  profile = ENV['PROFILE'] || 'default'
>  t.cucumber_opts = "--profile #{profile}"
> end
>
> In the end I opted to just call Cucumber from the commandline:
>
> desc "run stories"
> task :runner do
>  cucumber = "cucumber stories"
>  sh cucumber
> end
>
> And then add a helper file to my stories directory and tell my steps to
> load the Rails environment, such that my_steps.rb looks like this:
>
> require 'spec'
> require File.expand_path(File.dirname(__FILE__) + "/../../helper")
>
> # then all my step code......
>
> And my helper.rb file looks like this:
>
> ENV["RAILS_ENV"] = "test"
> require File.expand_path(File.dirname(__FILE__) +
> "/../config/environment")
>
>
> So is this the correct way for adding a Rake task to the main Rails Rake
> file so that it will run all my stories?
> Should I still include the old all.rb file in the stories directory so
> that I can run it without using Rake?
>
> Many thanks
>
> BE...
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>



-- 
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com


More information about the rspec-users mailing list