I am trying to run some cucumber tests using rake. When I call rake kickoff (#kickoff is the tag within my feature file) I get the following error:
rake aborted!
NoMethodError: undefined method `initializer' for Cucumber:Module
/webdata/jenkins/jobs/kickoff_build/workspace/Rakefile:2:in `<top (required)>'
(See full trace by running task with --trace)
I have already run bundler and all necessary gems are installed.
Here is the contents of my kickoff_build feature file:
#kickoff
Feature: Automated Regression Build
Scenario: As an automation developer, I want to kick off the build
Given the CI server is configured correctly
When the tag in line 1 of this file is called via a rake task
Then this test should run and pass
Here is the content of my Rakefile:
require 'rubygems'
require 'cucumber'
require 'cucumber/rake/task'
require 'cuke_sniffer'
Cucumber::Rake::Task.new(:kickoff, :build) do |t|
tags = '--tags ~#wip --tags ~#manual --tags ~#known_defect'
t.cucumber_opts = "--format html --out results/result.html --format pretty #{tags} --format junit --out features/reports"
end
This is a bug present in the betas for cucumber 2.0.0.
Upgrade to cucumber ~> 2.0 and you should be fine.
Related
I would like to do the testfirst.org exercises although can't seem to get to the starting line due to a version issue/lack of knowledge on my part as well..
At the begining you have to run the test $rake
i got following error..
(in /home/arno/learn_ruby)
rake aborted!
Gem::MissingSpecError: Could not find 'rspec' (~> 2) among 94 total
gem(s)
Checked in
'GEM_PATH=/home/arno/.gem/ruby/2.4.0:/home/arno/.rbenv/
versions/2.4.0/lib/ruby/gems/2.4.0', execute `gem env` for more
information
/home/arno/learn_ruby/Rakefile:2:in `<top (required)>'
(See full trace by running task with --trace)
I then tried to uninstall rspec. I then tried to install a version less than 3. That also did not work. Now I have version 2.9 and 3.2 installed but the same error persisted..
I then did bundle install and bundle update...something changed although still not working..
Here is the latest error when i run the test $rake..
(in /home/arno/learn_ruby)
rake aborted!
NoMethodError: undefined method `last_comment' for #
<Rake::Application:0x00564ff13bf4b0>
/home/arno/learn_ruby/Rakefile:8:in `new'
/home/arno/learn_ruby/Rakefile:8:in `<top (required)>'
(See full trace by running task with --trace)
Here is the rakefile..
# This Rakefile has all the right settings to run the tests inside
each lab
gem 'rspec', '~>2'
require 'rspec/core/rake_task'
task :default => :spec
desc "run tests for this lab"
RSpec::Core::RakeTask.new do |task|
lab = Rake.application.original_dir
task.pattern = "#{lab}/*_spec.rb"
task.rspec_opts = [ "-I#{lab}", "-I#{lab}/solution", '-f
documentation', '-r ./rspec_config']
task.verbose = false
end
After 2 days of searching i found a solution from The Odin Project.
They have a Test First - Rspec 3 edition..
If your having the same issue go to their repo https://github.com/TheOdinProject/learn_ruby.
Read through the readme file, fork that repo, clone your version of the repo, cd into it and bundle install..
All works fine now..
I have some classes with unit tests and I have a rake task to run these unit tests. However, I'm running into a problem where when the tests are run via rake an old version of minitest is being used. How can I get rake to use the newer version?
If I use the Minitest::Test subclass it runs fine when the tests are directly run through the ruby
command-line. However, if I use the following rake task:
require 'rake/testtask'
Rake::TestTask.new do |t|
t.pattern = 'tests/**/*_test.rb'
end
When I check the minitest version using puts MiniTest::Unit::VERSION it prints 5.5.0 when run with ruby, but prints 4.3.2 when run with rake. (When using gem list minitest -d version 4.3.2 is listed as the default.)
The reason I want to use the newer version of minitest is that when I directly run the unit tests using Ruby 2.0 I get the following warning:
MiniTest::Unit::TestCase is now Minitest::Test.
However, if I change MiniTest::Unit::TestCase to Minitest::Test I get the following error when I run the tests using rake.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rake/ext/module.rb:36:in `const_missing': uninitialized constant MiniTest::Test (NameError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/minitest/unit.rb:28:in `const_missing'
I want to avoid requiring any changes to the system configuration, because I want these tests to run on the default OS X ruby installation.
Using gem 'minitest', '=5.5.0' does not change the version of minitest that gets used.
Possibility #1: Run Rake with bundle exec to force it to use the version of Minitest managed by Bundler:
bundle exec rake test
Possibility #2: Create a binstub for Rake for your project that will load your bundle automatically:
bundle binstub rake
After that, you should be able to run Rake without bundle exec to get the same result.
Caveat: This has worked for the Ruby environment managers I've used recently, but you might need to Google around for a solution if it doesn't work for you.
Ruby is having a hard time loading minitest from the gem instead of the standard library, so we need to give it a little help. Add the following to your helper or rake task:
gem "minitest"
That will tell ruby to use the gem version. Just be sure to add that before minitest is required.
My micro Ruby project tests works on my machine, on private VM, but fails on Travis CI bulid
Project uses both rspec (+rspec-given) and minitest
Full trace here: https://travis-ci.org/equivalent/code_katas/jobs/61321482
$ bundle exec rake
MiniTest::Unit::TestCase is now Minitest::Test. From /home/travis/.rvm/rubies/ruby
2.1.4/lib/ruby/2.1.0/test/unit/testcase.rb:8:in `<module:Unit>'
/home/travis/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/test/unit.rb:676:in `<class:Runner>': undefined method `_run_suite' for class `Test::Unit::Runner' (NameError)
from /home/travis/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/test/unit.rb:261:in `<module:Unit>'
from /home/travis/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/test/unit.rb:15:in `<module:Test>'
from /home/travis/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/test/unit.rb:7:in `<top (required)>'
from /home/travis/build/equivalent/code_katas/vendor/bundle/ruby/2.1.0/gems/sorcerer-1.0.2/test/sorcerer/resource_test.rb:3:in `require'
#...
The error is self-explanatory MiniTest::Unit::TestCase is now Minitest::Test. This is caused by rspec-given dependency sorcerer using test-unit (source) (My code is not referring to test-unit anywhere in the code)
So the thing I'm curious about is if anyone know how to get around this.
Like I said it works everywhere else except Travis CI
Problem was that Travis CI is cloning repository into /home/travis/build/username/projectname and then bundle install with
--deployment flag which install gems to vendor folder
/home/travis/build/username/projectname/verdor
my Rakefile was using test pattern **/*_test.rb therefore run tests in all folders, therefore it was loading verdor directory and all the tests from dependencies (external gems) some of which were TestUnit not compatible with MiniTest
solution was to load tests in Rakefile not with pattern but with:
Rake::TestTask.new(:test) do |t|
t.test_files = Dir['**/*_test.rb'].reject do |path|
path.include?('vendor') # tell travis CI to ignore vendor tests
end
end
similar apply for RSpec
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = Dir.glob('**/*_spec.rb').reject do |path|
path.include?('vendor') # tell travis CI to ignore vendor tests
end
# t.rspec_opts = '--format documentation'
end
every one
I am new with cucumber & rake in ruby. I have completed a example of cucumber test. My test run ok in Ruby Mine by jetbrain (well, hook Before & After work well). When I try to using Cucumber rake task to start cucumber, the cucumber start and run well except the hook script. I found that both Before and After hook (and another hook) doesn't call when rake run the cucumber job
require 'cucumber'
require 'cucumber/rake/task'
require 'rubygems'
require 'rake'
require File.dirname(__FILE__) + "/features/support/selenum_drivers"
task :features => [:chrome_runner]
Cucumber::Rake::Task.new (:chrome_runner) do |t|
SeleniumCommon.configure do |config|
config.selenium_chrome = true
end
t.cucumber_opts = "config=chrome features -f pretty -f progress -r features/all_features -r features/step_definitions"
end
Here is my Rake
Any idea for this.
Thank you
You might try using the cucumber.yml for the cucumber_opts, and placing the other configuration in a support file.
Here a gist I use for javascript, chrome, headless and more.
I have a problem, my rake file looks like this:
require File.expand_path('../config/application', __FILE__)
require 'cucumber'
require "cucumber/rake/task"
Whois::Application.load_tasks
Cucumber::Rake::Task.new(:features) do |t|
t.cucumber_opts = "features --format pretty"
end
And the main reason of importing cucumber is to run tests with CI. But recently I've got a problem.
When I deployed to heroku and tried to run heroku run rake assets:precompile, I've got:
rake aborted!
no such file to load -- cucumber
As far as I understand, it can't find the cucumber that's only available in test env.
How can I tell rake, to use cure only in test env?
You'd need to wrap it in something like;
if Rails.env.test?
require 'cucumber'
require "cucumber/rake/task"
end