Hi Guys,
Im in a bit of a Pickle. Im using Watir-Webdriver with Cucumber but the language im coding in is RUBY.
we have a new folder structure which is:
-git_repo
> -lib > -bin > -features > -project_1 > -step_definitions > -support > -env.rb > -feature_files > -project_2 > -step_definitions > -support > -env.rb > -feature_files > -common_project > -support > -env.rb > -feature_files > -support > -env.rb
The problem I am having is in the common_project folder there is only a feature file. The step definitions sit in the respected projects (project_1 or project_2). So This will allow me to run a regression test picking up tests from common_project and project_1 or common_project and project_2.
The env.rb file in all three projects (project_1, project_2 and common_project) looks something like this:
Dir["features/support/env.rb"].each {|file| require file }
So all the env.rb files are pointing to one single env.rb file. The env.rb file which sits in features/support/ looks like this:
require 'rubygems' require 'bundler/setup'
VENTURE = $environment[:venture]
def require_files(venture_type) Dir.glob(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'common', '**', '*.rb')).each{|file| require file} Dir["lib/pages/#{venture_type}/mixins/*.rb"].each {|file| require file} Dir.glob(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'pages', "#{venture_type}", '**', '*.rb')).each{|file| require file} end
if VENTURE == 'www.jackpotjoy' or VENTURE == 'www.botemania' or VENTURE == 'de.jackpotjoy' puts 'WHITELABEL VENTURES' require_files 'whitelabel' else puts 'CLONE VENTURES' require_files 'clones' end
def start_browser puts "------------------ firefox port: #{PORT} -----------------" @browser = Watir::Browser.new(:firefox, {:port => PORT}) end
After do @browser.close end
The problem i am facing is that when i try to run a single feature from the common_project it is not picking up the step_definitions from the respected project.
So if I change the env,rb file in the common_project to pick up the step_definitions from the respected project i change the env.rb file to this:
Dir["features/support/env.rb"].each {|file| require file }
def require_files(venture_type) Dir["features/#{venture_type}/step_definitions/*.rb"].each {|file| require file } end
if VENTURE == 'www.jackpotjoy' or VENTURE == 'www.botemania' or VENTURE == 'de.jackpotjoy' puts 'WHITELABEL VENTURES' require_files 'whitelabel' else puts 'CLONE VENTURES' require_files 'clones' end
Then I am able to run a single feature from the common_project. (the command i use is: ruby bin/runtests -e trunk-auto -t piquette -l en -v jpj -- features/common_project)
BUT this is where the problem lies, I need to be able to run both projects together which i am able to do. But when the common_project env.rb file is changed to the one above then i get Ambiguous step errors. This is because the step_definitions are getting loaded twice.
The command im using to run the tests together is: ruby bin/runtests -e trunk-auto -t piquette -l en -v jpj -- features/ common_project feature/project_1
So the question is... Is there any way that I can ONLY require the step_definitions to the common_project ONLY if the step_definitions are not loaded. So if i try to just run the common_project then it will run and if I run project_1 and common_project together I will not get ambiguous steps errors?
Any help would be great. Ive tried looking into the cucumber source code but was not able to find anything, I've tried requiring the step_definitions in a different way and still no success...
Any help, solution, tips would be really really appreciated.
Once again, i'm sorry to disturb you so late in the day.
Kind regards, Usman Hussain