From d2d99f4cc6792dac8af5e5ab8109ce8018b3be0b Mon Sep 17 00:00:00 2001 From: Xavier Shay Date: Sat, 22 Mar 2014 16:59:08 -0700 Subject: [PATCH] Extract infer file type code into own file. --- lib/rspec/rails.rb | 2 + lib/rspec/rails/configuration.rb | 63 +++++++++++++++++++++++++++++++ lib/rspec/rails/example.rb | 64 -------------------------------- 3 files changed, 65 insertions(+), 64 deletions(-) create mode 100644 lib/rspec/rails/configuration.rb diff --git a/lib/rspec/rails.rb b/lib/rspec/rails.rb index b74d0a125e..b02433170f 100644 --- a/lib/rspec/rails.rb +++ b/lib/rspec/rails.rb @@ -14,3 +14,5 @@ require 'rspec/rails/fixture_support' require 'rspec/rails/example' require 'rspec/rails/vendor/capybara' + +require 'rspec/rails/configuration' diff --git a/lib/rspec/rails/configuration.rb b/lib/rspec/rails/configuration.rb new file mode 100644 index 0000000000..af72a1be90 --- /dev/null +++ b/lib/rspec/rails/configuration.rb @@ -0,0 +1,63 @@ +RSpec::configure do |c| + def c.escaped_path(*parts) + Regexp.compile(parts.join('[\\\/]') + '[\\\/]') + end + + controller_path_regex = c.escaped_path(%w[spec controllers]) + c.include RSpec::Rails::ControllerExampleGroup, + :type => :controller, + :file_path => lambda { |file_path, metadata| + metadata[:type].nil? && controller_path_regex =~ file_path + } + + helper_path_regex = c.escaped_path(%w[spec helpers]) + c.include RSpec::Rails::HelperExampleGroup, + :type => :helper, + :file_path => lambda { |file_path, metadata| + metadata[:type].nil? && helper_path_regex =~ file_path + } + + mailer_path_regex = c.escaped_path(%w[spec mailers]) + if defined?(RSpec::Rails::MailerExampleGroup) + c.include RSpec::Rails::MailerExampleGroup, + :type => :mailer, + :file_path => lambda { |file_path, metadata| + metadata[:type].nil? && mailer_path_regex =~ file_path + } + end + + model_path_regex = c.escaped_path(%w[spec models]) + c.include RSpec::Rails::ModelExampleGroup, + :type => :model, + :file_path => lambda { |file_path, metadata| + metadata[:type].nil? && model_path_regex =~ file_path + } + + request_path_regex = c.escaped_path(%w[spec (requests|integration|api)]) + c.include RSpec::Rails::RequestExampleGroup, + :type => :request, + :file_path => lambda { |file_path, metadata| + metadata[:type].nil? && request_path_regex =~ file_path + } + + routing_path_regex = c.escaped_path(%w[spec routing]) + c.include RSpec::Rails::RoutingExampleGroup, + :type => :routing, + :file_path => lambda { |file_path, metadata| + metadata[:type].nil? && routing_path_regex =~ file_path + } + + view_path_regex = c.escaped_path(%w[spec views]) + c.include RSpec::Rails::ViewExampleGroup, + :type => :view, + :file_path => lambda { |file_path, metadata| + metadata[:type].nil? && view_path_regex =~ file_path + } + + feature_example_regex = c.escaped_path(%w[spec features]) + c.include RSpec::Rails::FeatureExampleGroup, + :type => :feature, + :file_path => lambda { |file_path, metadata| + metadata[:type].nil? && feature_example_regex =~ file_path + } +end diff --git a/lib/rspec/rails/example.rb b/lib/rspec/rails/example.rb index 83468e5e60..0a6902e56a 100644 --- a/lib/rspec/rails/example.rb +++ b/lib/rspec/rails/example.rb @@ -7,67 +7,3 @@ require 'rspec/rails/example/routing_example_group' require 'rspec/rails/example/model_example_group' require 'rspec/rails/example/feature_example_group' - -RSpec::configure do |c| - def c.escaped_path(*parts) - Regexp.compile(parts.join('[\\\/]') + '[\\\/]') - end - - controller_path_regex = c.escaped_path(%w[spec controllers]) - c.include RSpec::Rails::ControllerExampleGroup, - :type => :controller, - :file_path => lambda { |file_path, metadata| - metadata[:type].nil? && controller_path_regex =~ file_path - } - - helper_path_regex = c.escaped_path(%w[spec helpers]) - c.include RSpec::Rails::HelperExampleGroup, - :type => :helper, - :file_path => lambda { |file_path, metadata| - metadata[:type].nil? && helper_path_regex =~ file_path - } - - mailer_path_regex = c.escaped_path(%w[spec mailers]) - if defined?(RSpec::Rails::MailerExampleGroup) - c.include RSpec::Rails::MailerExampleGroup, - :type => :mailer, - :file_path => lambda { |file_path, metadata| - metadata[:type].nil? && mailer_path_regex =~ file_path - } - end - - model_path_regex = c.escaped_path(%w[spec models]) - c.include RSpec::Rails::ModelExampleGroup, - :type => :model, - :file_path => lambda { |file_path, metadata| - metadata[:type].nil? && model_path_regex =~ file_path - } - - request_path_regex = c.escaped_path(%w[spec (requests|integration|api)]) - c.include RSpec::Rails::RequestExampleGroup, - :type => :request, - :file_path => lambda { |file_path, metadata| - metadata[:type].nil? && request_path_regex =~ file_path - } - - routing_path_regex = c.escaped_path(%w[spec routing]) - c.include RSpec::Rails::RoutingExampleGroup, - :type => :routing, - :file_path => lambda { |file_path, metadata| - metadata[:type].nil? && routing_path_regex =~ file_path - } - - view_path_regex = c.escaped_path(%w[spec views]) - c.include RSpec::Rails::ViewExampleGroup, - :type => :view, - :file_path => lambda { |file_path, metadata| - metadata[:type].nil? && view_path_regex =~ file_path - } - - feature_example_regex = c.escaped_path(%w[spec features]) - c.include RSpec::Rails::FeatureExampleGroup, - :type => :feature, - :file_path => lambda { |file_path, metadata| - metadata[:type].nil? && feature_example_regex =~ file_path - } -end