File tree Expand file tree Collapse file tree 4 files changed +76
-0
lines changed Expand file tree Collapse file tree 4 files changed +76
-0
lines changed Original file line number Diff line number Diff line change 10
10
require 'rspec/rails/matchers'
11
11
require 'rspec/rails/fixture_support'
12
12
require 'rspec/rails/file_fixture_support'
13
+ require 'rspec/rails/fixture_file_upload_support'
13
14
require 'rspec/rails/example'
14
15
require 'rspec/rails/vendor/capybara'
15
16
require 'rspec/rails/configuration'
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
+ delegate :fixture_file_upload , :to => :rails_fixture_file_wrapper
6
+
7
+ private
8
+
9
+ def rails_fixture_file_wrapper
10
+ resolved_fixture_path = ( fixture_path || RSpec . configuration . fixture_path || '' )
11
+ RailsFixtureFileWrapper . fixture_path = File . join ( resolved_fixture_path , '' )
12
+ RailsFixtureFileWrapper . instance
13
+ end
14
+
15
+ class RailsFixtureFileWrapper
16
+ include ActionDispatch ::TestProcess if defined? ( ActionDispatch ::TestProcess )
17
+
18
+ class << self
19
+ attr_reader :fixture_path
20
+
21
+ # Get the instance of wrapper
22
+ def instance
23
+ @instance ||= new
24
+ end
25
+
26
+ # Override fixture_path set
27
+ # to support Rails 3.0->3.1 using ActionController::TestCase class to resolve fixture_path
28
+ # see https://apidock.com/rails/v3.0.0/ActionDispatch/TestProcess/fixture_file_upload
29
+ def fixture_path = ( value )
30
+ if ActionController ::TestCase . respond_to? ( :fixture_path )
31
+ ActionController ::TestCase . fixture_path = value
32
+ end
33
+ @fixture_path = value
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