Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/rspec/rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ def render_views?
rendering_views
end

def infer_spec_type_from_file_location!
DIRECTORY_MAPPINGS.each do |type, dir_parts|
def infer_spec_type_from_file_location!(list = {})
custom = list.inject({}) do |r, (k, v)|
dir = v ? v.to_s : "#{ k }s"
r[k] = ['spec', dir]
r
end

DIRECTORY_MAPPINGS.merge(custom).each do |type, dir_parts|
escaped_path = Regexp.compile(dir_parts.join('[\\\/]') + '[\\\/]')
define_derived_metadata(:file_path => escaped_path) do |metadata|
metadata[:type] ||= type
Expand Down
24 changes: 24 additions & 0 deletions spec/rspec/rails/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,30 @@ def in_inferring_type_from_location_environment
include_examples "infers type from location", :routing, "spec/routing"
include_examples "infers type from location", :view, "spec/views"
include_examples "infers type from location", :feature, "spec/features"

context "with a custom definition" do
context "use an array" do
def in_inferring_type_from_location_environment
in_sub_process do
RSpec.configuration.infer_spec_type_from_file_location!([:worker])
yield
end
end

include_examples "infers type from location", :worker, "spec/workers"
end

context "use a hash" do
def in_inferring_type_from_location_environment
in_sub_process do
RSpec.configuration.infer_spec_type_from_file_location!(sidekiq: :workers)
yield
end
end

include_examples "infers type from location", :sidekiq, "spec/workers"
end
end
end

it "fixture support is included with metadata `:use_fixtures`" do
Expand Down