testdouble / jasmine-rails

A Jasmine runner for rails projects that's got you covered in both the terminal and the browser
http://rubygems.org/gems/jasmine-rails
MIT License
377 stars 154 forks source link

Fix spec_dir lookup when Dir.pwd is not Rails.root #227

Open kurko opened 6 years ago

kurko commented 6 years ago

Context

I was able to get this gem to work with my engine by going inside the test_app dir and running

bundle exec rails spec:javascript

So far so good. The problem is that I don't want to have to run cd spec/test_app every time to run my Javascript tests. I want to run them from the engine's grandparent directory so I can include it in my Rakefile for the entire test suite. In other words, this is my dir tree:

~/engine/
~/engine/spec/javascripts/
~/engine/spec/test_app/spec/javascripts/support/jasmine.yml

Rails.root is always ~/engine/spec/test_app/, regardless of whether I'm in `~/engine/ or not.

The problem

Look at this line:

[paths].flatten.map { |path| Dir.glob path }.flatten.collect { |path| Rails.root.join(path) }

Dir.glob path, equivalent to Dir.glob("spec/javascripts") returns true because Dir.pwd is ~/engine/, therefore ~/engine/spec/javascripts exists.

However, the last collect has Rails.root.join("spec_javascript), which will map to ~/engine/spec/test_app/spec/javascripts, but there's nothing there (because my test files were configured to ~/engine/spec/javascript).

To "fix that, I put ../javascripts in my yml's spec_dir, but no Dir.glob just returns false because, in fact, ~/engine/../javascripts doesn't exist. So, the code is verifying one path and resolving to some other.

The fix

-      [paths].flatten.map { |path| Dir.glob path }.flatten.collect { |path| Rails.root.join(path) }
+      [paths].flatten.map { |path| Dir.glob(Rails.root.join(path)) }.flatten.collect { |path| Rails.root.join(path) }

This fix just makes it cohesive.

I suspect this is in a way connected with https://github.com/searls/jasmine-rails/issues/102 (to make it work with engines).

kurko commented 6 years ago

erm, don't think the failure is related:

<--- Running rake spec:javascript
rake aborted!
NoMethodError: private method `include' called for ActionDispatch::Assertions:Module
/home/travis/.rvm/gems/ruby-2.0.0-p648/gems/turbolinks-5.1.0/lib/turbolinks.rb:25:in `block (2 levels) in <class:Engine>'