[RUBY] Test Active Strage with RSpec

Introduction

I'm working on an app that allows you to post images using Active Strage. Here is an example of how to write a test at that time.

factories

FactoryBot.define do
  factory :post do
...
      trait :post_image do
        image {
          fixture_file_upload("app/assets/images/XXX.PNG")
        }
      end
...

define let


let(Definition name) {Definition content}

let(:post_image) { FactoryBot.create(:post_image) }

To use (example)

post = FactoryBot.create(:post,:post_image)

The site that I used as a reference

https://qiita.com/maca12vel/items/ee4d16827f24f69080ae https://shuttodev.hatenablog.com/entry/2019/09/04/015756

Recommended Posts

Test Active Strage with RSpec
[Rails] Test with RSpec
Test Nokogiri with Rspec.
Test GraphQL resolver with rspec
Test with RSpec + Capybara + selenium + chromedriver
Copy and paste test with RSpec
Let's unit test with [rails] Rspec!
[Ruby on Rails] View test with RSpec
[Ruby on Rails] Controller test with RSpec
[Ruby on Rails] Model test with RSpec
I want to test Action Cable with RSpec test
I rewrote the Rails tutorial test with RSpec
[For beginners] Test devise user registration with RSpec
Integration Test with Gradle
Introduction to RSpec 1. Test, RSpec
Testing model with RSpec
Use webmock with Rspec
Automatically test with Gauge
Load test with JMeter
Unit test with Junit.
[Ruby on Rails] Delete s3 images with Active Strage
Introduction to RSpec 4. Create test data with Factory Bot
Test Web API with junit
How to test a private method with RSpec for yourself
[Rails] Test code using Rspec
Remote debugging with Gradle test
[Rails] About Rspec response test
How to erase test image after running Rspec test with CarrierWave
Post videos with Active Storage
Understand code coverage with Rspec, the Ruby on Rails test framework
Image upload using CarrierWave ~ Rspec test ~
REST API test with REST Assured Part 2
RSpec ~ Task model validation test creation
Output test coverage with clover + gradle
[Rails5] Rspec -Unit test when nesting-
About app testing RSpec (unit test)
[Java] Test private methods with JUnit
Test list inclusion relationships with AssertJ
[RSpec] How to write test code
Test Spring framework controller with Junit
[RSpec] Unit test (using gem: factory_bot)