Creating records (models) from step definitions using attachtments in cucumber

Creating records (models) from step definitions using attachtments in cucumber

This is an example using step definitions in cucumber for creating a models that uses paperclip attachments:

My Factory content:


FactoryGirl.define do |box|
 factory :spree_banner_box, :class => 'Spree::BannerBox' do
   alt_text ''
   url ''
   enabled true
 end
end


My file is features/step_definitions/banners_step.rb and the content:


Given(/^The defaults banners are created$/) do
 14.times do |x|
   box = "box-#{ x + 1 }"
   banner_values = {
     alt_text: '',
     url: '',
     category: box,
     banner_type: 'photo',
     attachment: File.new("#{Rails.root}/spec/fixtures/images/home/#{ box }.png"),
     enabled: true
   }
   FactoryGirl.create :spree_banner_box, banner_values
 end

 5.times do |box|
  box_category = "box-#{ box + 1 }-text"
  banner_values = {
    alt_text: '',
    url: '',
    category: box_category,
    banner_type: 'text',
    attachment: File.new("#{Rails.root}/spec/fixtures/images/home/#{ box_category }.png"),
    enabled: true
  }
  FactoryGirl.create :spree_banner_box, banner_values
 end
end

And now we can use it in our feature
my file is located in features/banners.feature:

@javascript

Feature: My feature
  Background:
    Given The defaults banners are created
No Comments

Post A Comment