File tree Expand file tree Collapse file tree 4 files changed +71
-0
lines changed Expand file tree Collapse file tree 4 files changed +71
-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 @@ -83,6 +83,8 @@ def self.initialize_configuration(config)
83
83
if ::Rails ::VERSION ::STRING > '5'
84
84
config . add_setting :file_fixture_path , :default => 'spec/fixtures/files'
85
85
config . include RSpec ::Rails ::FileFixtureSupport
86
+ elsif ::Rails ::VERSION ::STRING >= '3'
87
+ config . include RSpec ::Rails ::FixtureFileUploadSupport
86
88
end
87
89
# This allows us to expose `render_views` as a config option even though it
88
90
# breaks the convention of other options by using `render_views` as a
Original file line number Diff line number Diff line change
1
+ require 'singleton'
2
+
3
+ module RSpec
4
+ module Rails
5
+ # @private
6
+ module FixtureFileUploadSupport
7
+ extend ActiveSupport ::Concern
8
+
9
+ included do
10
+ delegate :fixture_file_upload , :to => :rails_test_wrapper
11
+ end
12
+
13
+ private
14
+
15
+ def rails_test_wrapper
16
+ resolved_fixture_path = ( fixture_path || RSpec . configuration . fixture_path || '' )
17
+ RailsTestWrapper . fixture_path = File . join ( resolved_fixture_path , '' )
18
+ RailsTestWrapper . instance
19
+ end
20
+
21
+ class RailsTestWrapper
22
+ include Singleton
23
+ cattr_accessor :fixture_path
24
+
25
+ def self . fixture_path = ( value )
26
+ if ActionController ::TestCase . respond_to? ( :fixture_path )
27
+ ActionController ::TestCase . fixture_path = value
28
+ end
29
+ @@fixture_path = value
30
+ end
31
+
32
+ if defined? ( ActionDispatch ::TestProcess )
33
+ include ActionDispatch ::TestProcess
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe RSpec ::Rails ::FixtureFileUploadSupport do
4
+ context 'with fixture path set in config' do
5
+ before { RSpec . configuration . fixture_path = File . dirname ( __FILE__ ) }
6
+
7
+ it 'resolves fixture file' do
8
+ expect ( fixture_file_upload_resolved . run ) . to be true
9
+ end
10
+ end
11
+
12
+ context 'with fixture path set in spec' do
13
+ it 'resolves fixture file' do
14
+ expect ( fixture_file_upload_resolved ( File . dirname ( __FILE__ ) ) . run ) . to be true
15
+ end
16
+ end
17
+
18
+ def fixture_file_upload_resolved ( fixture_path = nil )
19
+ RSpec ::Core ::ExampleGroup . describe do
20
+ include RSpec ::Rails ::FixtureFileUploadSupport
21
+
22
+ self . fixture_path = fixture_path if fixture_path
23
+
24
+ it 'supports fixture file upload' do
25
+ file = fixture_file_upload ( File . basename ( __FILE__ ) )
26
+ expect ( file . read ) . to match ( /describe FixtureFileUploadSupport/im )
27
+ end
28
+ end
29
+ end
30
+ end
You can’t perform that action at this time.
0 commit comments