Skip to content

Commit

Permalink
Extract infer file type code into own file.
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviershay committed Mar 23, 2014
1 parent fcc74ca commit d2d99f4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 64 deletions.
2 changes: 2 additions & 0 deletions lib/rspec/rails.rb
Expand Up @@ -14,3 +14,5 @@
require 'rspec/rails/fixture_support'
require 'rspec/rails/example'
require 'rspec/rails/vendor/capybara'

require 'rspec/rails/configuration'
63 changes: 63 additions & 0 deletions 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
64 changes: 0 additions & 64 deletions lib/rspec/rails/example.rb
Expand Up @@ -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

0 comments on commit d2d99f4

Please sign in to comment.