I solved using
FactoryBot.define do
factory :culture do
name 'Soy'
after(:build) do |culture|
culture.image.attach(io: File.open(Rails.root.join('spec', 'factories', 'images', 'soy.jpeg')), filename: 'soy.jpeg', content_type: 'image/jpeg')
end
end
end
After
describe '#image' do
subject { create(:culture).image }
it { is_expected.to be_an_instance_of(ActiveStorage::Attached::One) }
end
Related Contents:
- How to run a single RSpec test?
- Rails: Missing host to link to! Please provide :host parameter or set default_url_options[:host]
- How to check for a JSON response using RSpec?
- How to get current path with query string using Capybara
- How to set request headers in rspec request spec?
- Rspec, Rails: how to test private methods of controllers?
- How to say “should_receive” more times in RSpec
- rspec 3 – stub a class method
- RSpec controller testing – blank response.body
- How to test exception raising in Rails/RSpec?
- Rails 4: How to reset test database?
- How to get Rails.logger printing to the console/stdout when running rspec?
- How do I prepare test database(s) for Rails rspec tests without running rake spec?
- RSpec: What is the difference between let and a before block?
- Generate a controller with all the RESTful functions
- Factory-girl create that bypasses my model validation
- capybara assert attributes of an element
- Rspec 3 how to test flash messages
- rails rspec before all vs before each
- How to test ActionMailer deliver_later with rspec
- Running ruby debug in rspec?
- Ruby on Rails: Switch from test_unit to rspec
- Rspec Output Format: Documentation
- What is the purpose of a `transient do` block in FactoryBot factories?
- Rails/Rspec Make tests pass with http basic authentication
- undefined method `get’ for #
- Rails 3.1, RSpec: testing model validations
- Shoulda/RSpec matchers – conditional validation
- Rails 5, Rspec: Environment data not found in the schema
- how to test params passed into a controller in rails 3, using rspec?
- How to stub ApplicationController method in request spec
- Clearing out ActionMailer::Base.deliveries after RSpec test
- Rails rspec set subdomain
- RSpec documentation…where is it hiding?
- How to spec a private method
- Visit method not found in my rspec
- Running a spec in RubyMine results in “cannot load such file — teamcity/spec/runner/formatter/teamcity/formatter (LoadError)”
- Rails : RuntimeError – can’t modify frozen Array when running rspec in rails
- Is it impossible to use Guard with RubyMine?
- Set Rspec default GET request format to JSON
- Get path to ActiveStorage file on disk
- How to test rendering a partial with RSpec
- How to force an RSpec test to fail?
- expected true to respond to true?
- Controller Specs vs Request Specs?
- How to include Rails Helpers on RSpec
- How to test ApplicationController method defined also as a helper method?
- Rspec – Rails – How to follow a redirect
- Why not use shared ActiveRecord connections for Rspec + Selenium?
- Stop Rails generating spec tests for views and helpers?