Reputation: 329
Given I have defined the following modules in my features/support directory
module Api
class User
...
end
...
end
and also
module Web
class User
...
end
...
end
in my env.rb file I have
require File.expand_path(File.dirname(__FILE__)+'/webworld')
require File.expand_path(File.dirname(__FILE__)+'/apiworld')
if ENV['USE_API'] == 1
World(Api)
else
World(Web)
end
So if I try to use this construct in a step definition like
Given /^a user is created$/ do
@user = User.new
end
And run cucumber
, my ruby interpreter will give me the this output
uninitialized constant User (NameError) ./features/step_definitions/user_steps.rb:17: [...]
How to make this work? Is there a way or am I thinking i the wrong direction. I am pretty new to ruby - so I don't really know what it can do and what it can not do.
Upvotes: 2
Views: 2403
Reputation: 1191
You can't use World
for this. World
is for mixing methods into the self
object in each stepdef.
Instead of this:
if ENV['USE_API'] == 1
World(Api)
else
World(Web)
end
Try this:
User = ENV['USE_API'] == 1 ? Api::User : Web::User
Upvotes: 2