File tree Expand file tree Collapse file tree 3 files changed +79
-0
lines changed Expand file tree Collapse file tree 3 files changed +79
-0
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,10 @@ def self.initialize_configuration(config)
81
81
config . add_setting :file_fixture_path , :default => 'spec/fixtures/files'
82
82
config . include RSpec ::Rails ::FileFixtureSupport
83
83
end
84
+
85
+ # Add support for fixture_path on fixture_file_upload
86
+ config . include RSpec ::Rails ::FixtureFileUploadSupport
87
+
84
88
# This allows us to expose `render_views` as a config option even though it
85
89
# breaks the convention of other options by using `render_views` as a
86
90
# 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_fixture_file_wrapper
9
+ end
10
+
11
+ private
12
+
13
+ def rails_fixture_file_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
+ # Override fixture_path set
29
+ # to support Rails 3.0..3.1 using ActionController::TestCase class to resolve fixture_path
30
+ # see https://apidock.com/rails/v3.0.0/ActionDispatch/TestProcess/fixture_file_upload
31
+ def fixture_path = ( value )
32
+ if ActionController ::TestCase . respond_to? ( :fixture_path )
33
+ ActionController ::TestCase . fixture_path = value
34
+ end
35
+ @fixture_path = value
36
+ end
37
+
38
+ include ActionDispatch ::TestProcess if defined? ( ActionDispatch ::TestProcess )
39
+ end
40
+ end
41
+ end
42
+ end
43
+ 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