-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathfile_fixture.feature
56 lines (47 loc) · 1.58 KB
/
file_fixture.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Feature: Using `file_fixture`
Rails 5 adds simple access to sample files called file fixtures.
File fixtures are normal files stored in spec/fixtures/files by default.
File fixtures are represented as +Pathname+ objects.
This makes it easy to extract specific information:
```ruby
file_fixture("example.txt").read # get the file's content
file_fixture("example.mp3").size # get the file size
```
You can customize files location by setting
```ruby
RSpec.configure do |config|
config.file_fixture_path = "spec/custom_directory"
end
```
Scenario: Reading file content from fixtures directory
And a file named "spec/fixtures/files/sample.txt" with:
"""
Hello
"""
And a file named "spec/lib/file_spec.rb" with:
"""ruby
require "rails_helper"
RSpec.describe "file" do
it "reads sample file" do
expect(file_fixture("sample.txt").read).to eq("Hello")
end
end
"""
When I run `rspec spec/lib/file_spec.rb`
Then the examples should all pass
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