Skip to content

Commit

Permalink
Only return spec paths that are in spec directories
Browse files Browse the repository at this point in the history
Currently (in sprockets 3), Konacha.spec_paths returns all
specs found in any rails asset path, not just those within
the spec_dir
  • Loading branch information
ryanlower committed Jun 12, 2015
1 parent 0964be9 commit 6de7a5d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/konacha.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def spec_paths
elsif Rails.application.assets.respond_to?(:each_file)
paths = Rails.application.assets.each_file.find_all { |path|
pathname = Pathname.new(path)
config.spec_matcher === pathname.basename.to_s &&
pathname.dirname.to_s.start_with?(root) &&
config.spec_matcher === pathname.basename.to_s &&
(pathname.extname == '.js' || Tilt[pathname])
}
else
Expand Down
14 changes: 13 additions & 1 deletion spec/konacha_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,19 @@ def self.===(path)
end
end

context 'with additional spec directories' do
context 'with configured spec directories' do
around do |example|
begin
spec_dir = Konacha.config.spec_dir
Konacha.configure {|c| c.spec_dir = ["spec/javascripts", "app/sections"]}
# For Sprockets 3, adding to config.assets.paths does not work
if Rails.application.assets.respond_to?(:append_path)
Rails.application.assets.append_path(Rails.root.join("app/sections").to_s)
Rails.application.assets.append_path(Rails.root.join("spec/isolated").to_s)
# Sprockets 2
else
Rails.application.config.assets.paths << Rails.root.join("app/sections").to_s
Rails.application.config.assets.paths << Rails.root.join("spec/isolated").to_s
end
example.run
ensure
Expand All @@ -127,6 +129,16 @@ def self.===(path)
Konacha.spec_root.should include Rails.root.join("app/sections").to_s
subject.should include("my_section/my_section_spec.js.coffee")
end

# spec/isolated is in the assets path, but not Koncha's spec_dir
it 'does not have specs from spec/isolated' do
Konacha.spec_root.should_not include Rails.root.join("spec/isolated").to_s

spec_file = "isolated/errors/failing_iframe_spec.js.coffee"
# Ensure neither the relative or absolute paths are present
subject.should_not include(spec_file)
subject.should_not include(Rails.root.join("spec", spec_file).to_s)
end
end

end
Expand Down

0 comments on commit 6de7a5d

Please sign in to comment.