Skip to content

Commit

Permalink
Fixes issue with ActiveStorage::FixtureSet.blob erroring because Acti…
Browse files Browse the repository at this point in the history
…veStorage::FixtureSet.file_fixture_path is not set.
  • Loading branch information
jaywhy committed May 1, 2023
1 parent 1873102 commit 5c6f711
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions features/file_fixture.feature
Expand Up @@ -36,3 +36,22 @@ Feature: Using `file_fixture`
"""
When I run `rspec spec/lib/file_spec.rb`
Then the examples should all pass

@rails_post_7
Scenario: Creating a ActiveStorage::Blob from a file fixture
Given a file named "spec/fixtures/files/sample.txt" with:
"""
Hello
"""
And a file named "spec/lib/fixture_set_blob.rb" with:
"""ruby
require "rails_helper"
RSpec.describe "blob" do
it "creates a blob from a sample file" do
expect(ActiveStorage::FixtureSet.blob(filename: "sample.txt")).to include("sample.txt")
end
end
"""
When I run `rspec spec/lib/fixture_set_blob.rb`
Then the examples should all pass
15 changes: 15 additions & 0 deletions features/support/rails_versions.rb
@@ -0,0 +1,15 @@
def rails_version
string_version = ENV.fetch("RAILS_VERSION", "~> 7.0.0")
if string_version == "main" || string_version.nil?
Float::INFINITY
else
string_version[/\d[\.-]\d/].tr('-', '.')
end
end

Before "@rails_post_7" do |scenario|
if rails_version.to_f < 7.0
warn "Skipping scenario #{scenario.name} on Rails v#{rails_version}"
skip_this_scenario
end
end
3 changes: 3 additions & 0 deletions lib/rspec/rails/file_fixture_support.rb
Expand Up @@ -9,6 +9,9 @@ module FileFixtureSupport

included do
self.file_fixture_path = RSpec.configuration.file_fixture_path
if defined?(ActiveStorage::FixtureSet)
ActiveStorage::FixtureSet.file_fixture_path = RSpec.configuration.file_fixture_path
end
end
end
end
Expand Down

0 comments on commit 5c6f711

Please sign in to comment.