I want to attach a file, from a cucumber step:
When /^I attach an image/ do
page.attach_file("Image", File.join(fixture_path, "green_small.jpg"))
end
For some reason this results in /home/xxx/test/fixtures/green_small.jpg. Somewhere the default for fixture_path is test/fixtures in cucumber.
I am using rspec, so the path to the fixtures should be spec/fixtures. My Rspec spec_helper.rb has this configured:
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
end
I have already tried setting this in config/environments/test.rb without success.
Obviously, I can simply build the path myself, page.attach_file("Image", File.join(Rails.root, "spec", "fixtures", "green_small.jpg")) works. But that fixture_path is already there. Setting that correct and then using it, would make the steps just a little more portable and cleaner.
But this is not used by Cucumber. How do I get the correct url in cucumber?
How about you define Cucumber global variables in
Worldwhich is a rb file infeatures/supportFile
features/support/path_define.rbThen you can use
my_fixture_pathvariable anywhere in step definitions.Reference: https://github.com/cucumber/cucumber/wiki/A-Whole-New-World
Hope this helps.