|
| 1 | +RSpec.configure do |config| |
| 2 | + def config.infer_spec_type_from_file_location! |
| 3 | + def self.escaped_path(*parts) |
| 4 | + Regexp.compile(parts.join('[\\\/]') + '[\\\/]') |
| 5 | + end |
| 6 | + |
| 7 | + controller_path_regex = self.escaped_path(%w[spec controllers]) |
| 8 | + self.include RSpec::Rails::ControllerExampleGroup, |
| 9 | + :type => :controller, |
| 10 | + :file_path => lambda { |file_path, metadata| |
| 11 | + metadata[:type].nil? && controller_path_regex =~ file_path |
| 12 | + } |
| 13 | + |
| 14 | + helper_path_regex = self.escaped_path(%w[spec helpers]) |
| 15 | + self.include RSpec::Rails::HelperExampleGroup, |
| 16 | + :type => :helper, |
| 17 | + :file_path => lambda { |file_path, metadata| |
| 18 | + metadata[:type].nil? && helper_path_regex =~ file_path |
| 19 | + } |
| 20 | + |
| 21 | + mailer_path_regex = self.escaped_path(%w[spec mailers]) |
| 22 | + if defined?(RSpec::Rails::MailerExampleGroup) |
| 23 | + self.include RSpec::Rails::MailerExampleGroup, |
| 24 | + :type => :mailer, |
| 25 | + :file_path => lambda { |file_path, metadata| |
| 26 | + metadata[:type].nil? && mailer_path_regex =~ file_path |
| 27 | + } |
| 28 | + end |
| 29 | + |
| 30 | + model_path_regex = self.escaped_path(%w[spec models]) |
| 31 | + self.include RSpec::Rails::ModelExampleGroup, |
| 32 | + :type => :model, |
| 33 | + :file_path => lambda { |file_path, metadata| |
| 34 | + metadata[:type].nil? && model_path_regex =~ file_path |
| 35 | + } |
| 36 | + |
| 37 | + request_path_regex = self.escaped_path(%w[spec (requests|integration|api)]) |
| 38 | + self.include RSpec::Rails::RequestExampleGroup, |
| 39 | + :type => :request, |
| 40 | + :file_path => lambda { |file_path, metadata| |
| 41 | + metadata[:type].nil? && request_path_regex =~ file_path |
| 42 | + } |
| 43 | + |
| 44 | + routing_path_regex = self.escaped_path(%w[spec routing]) |
| 45 | + self.include RSpec::Rails::RoutingExampleGroup, |
| 46 | + :type => :routing, |
| 47 | + :file_path => lambda { |file_path, metadata| |
| 48 | + metadata[:type].nil? && routing_path_regex =~ file_path |
| 49 | + } |
| 50 | + |
| 51 | + view_path_regex = self.escaped_path(%w[spec views]) |
| 52 | + self.include RSpec::Rails::ViewExampleGroup, |
| 53 | + :type => :view, |
| 54 | + :file_path => lambda { |file_path, metadata| |
| 55 | + metadata[:type].nil? && view_path_regex =~ file_path |
| 56 | + } |
| 57 | + |
| 58 | + feature_example_regex = self.escaped_path(%w[spec features]) |
| 59 | + self.include RSpec::Rails::FeatureExampleGroup, |
| 60 | + :type => :feature, |
| 61 | + :file_path => lambda { |file_path, metadata| |
| 62 | + metadata[:type].nil? && feature_example_regex =~ file_path |
| 63 | + } |
| 64 | + end |
| 65 | +end |
0 commit comments