I am trying to test my application with cucumber and capybara. I have the following step definition:
Given(/^I fill in the create article form with the valid article data$/) do @article_attributes = FactoryGirl.build(:article) within("#new_article") do fill_in('article_title', with: @article_attributes.title) attach_file('article_image', @article_attributes.image) fill_in('article_description', with: @article_attributes.description) fill_in('article_key_words', with: @article_attributes.key_words) fill_in('article_body', with: @article_attributes.body) end
My factory article looks like this:
FactoryGirl.define do factory :article do sequence(:title) {|n| "Title #{n}"} description 'Description' key_words 'Key word' image { File.open(File.join(Rails.root, '/spec/support/example.jpg')) } body 'Lorem...' association :admin, strategy: :build end end
And this is my bootloader file:
# encoding: UTF-8 class ArticleImageUploader < CarrierWave::Uploader::Base storage :file def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end def extension_white_list %w(jpg jpeg gif png) end end
But every time I run this script, I get an ERROR message:
Given I fill in the create article form with the valid article data
I also found that FactoryGirl returns image:nil when I run FactoryGirl.build(:article) in my rails test console.
Can someone explain to me what I'm doing wrong, please?
source share