File tree Expand file tree Collapse file tree 4 files changed +75
-0
lines changed Expand file tree Collapse file tree 4 files changed +75
-0
lines changed Original file line number Diff line number Diff line change 9
9
require 'rspec/rails/view_rendering'
10
10
require 'rspec/rails/matchers'
11
11
require 'rspec/rails/fixture_support'
12
+ require 'rspec/rails/fixture_file_upload_support'
12
13
require 'rspec/rails/file_fixture_support'
13
14
require 'rspec/rails/example'
14
15
require 'rspec/rails/vendor/capybara'
Original file line number Diff line number Diff line change @@ -84,6 +84,9 @@ def self.initialize_configuration(config)
84
84
config . add_setting :file_fixture_path , :default => 'spec/fixtures/files'
85
85
config . include RSpec ::Rails ::FileFixtureSupport
86
86
end
87
+
88
+ config . include RSpec ::Rails ::FixtureFileUploadSupport
89
+
87
90
# This allows us to expose `render_views` as a config option even though it
88
91
# breaks the convention of other options by using `render_views` as a
89
92
# command (i.e. `render_views = true`), where it would normally be used
Original file line number Diff line number Diff line change
1
+ module RSpec
2
+ module Rails
3
+ # @private
4
+ module FixtureFileUploadSupport
5
+ extend ActiveSupport ::Concern
6
+
7
+ included do
8
+ delegate :fixture_file_upload , :to => :rails_test_wrapper
9
+ end
10
+
11
+ private
12
+
13
+ def rails_test_wrapper
14
+ resolved_fixture_path = ( fixture_path || RSpec . configuration . fixture_path || '' )
15
+ RailsFixtureFileWrapper . fixture_path = File . join ( resolved_fixture_path , '' )
16
+ RailsFixtureFileWrapper . instance
17
+ end
18
+
19
+ class RailsFixtureFileWrapper
20
+ class << self
21
+ attr_reader :fixture_path
22
+
23
+ # Get the instance of wrapper
24
+ def instance
25
+ @instance ||= new
26
+ end
27
+
28
+ if defined? ( ActionDispatch ::TestProcess )
29
+ include ActionDispatch ::TestProcess
30
+
31
+ # Rails 3.0..3.1 are using ActionController::TestCase to resolve fixture_path
32
+ # see https://apidock.com/rails/v3.0.0/ActionDispatch/TestProcess/fixture_file_upload
33
+ include ActionController ::TestCase
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ module RSpec ::Rails
4
+ describe FixtureFileUploadSupport do
5
+ context 'with fixture path set in config' do
6
+ before { RSpec . configuration . fixture_path = File . dirname ( __FILE__ ) }
7
+
8
+ it 'resolves fixture file' do
9
+ expect ( fixture_file_upload_resolved . run ) . to be true
10
+ end
11
+ end
12
+
13
+ context 'with fixture path set in spec' do
14
+ it 'resolves fixture file' do
15
+ expect ( fixture_file_upload_resolved ( File . dirname ( __FILE__ ) ) . run ) . to be true
16
+ end
17
+ end
18
+
19
+ def fixture_file_upload_resolved ( fixture_path = nil )
20
+ RSpec ::Core ::ExampleGroup . describe do
21
+ include RSpec ::Rails ::FixtureFileUploadSupport
22
+
23
+ self . fixture_path = fixture_path if fixture_path
24
+
25
+ it 'supports fixture file upload' do
26
+ file = fixture_file_upload ( File . basename ( __FILE__ ) )
27
+ expect ( file . read ) . to match ( /describe FixtureFileUploadSupport/im )
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
You can’t perform that action at this time.
0 commit comments