Skip to content
Browse files

Better spec_file? logic (fixes #187)

The current logic has two problems.

1. Doesn't detect "spec" argument as triggering Rspec runner, erroneously uses M instead.
2. When an earlier argument is a Ruby file that isn't a spec (such as `formatter.rb`) the spec detection gives false negative because it doesn't match the spec pattern.

This fix looks at the last argument instead (where options won't be) and matches on /^spec/. I think that's the only regexp necessary, but I left SPEC_FILE_REGEXP that was already there.
  • Loading branch information...
1 parent 37174af commit d5a2302ff1bfd0c70cc99f0971d5831942197d69 @turadg turadg committed Dec 8, 2012
Showing with 3 additions and 5 deletions.
  1. +3 −5 rubygem/lib/zeus/rails.rb
View
8 rubygem/lib/zeus/rails.rb
@@ -203,13 +203,11 @@ def cucumber
private
+ SPEC_DIR_REGEXP = /^spec/
SPEC_FILE_REGEXP = /.+_spec\.rb$/
def spec_file? argv
- SPEC_FILE_REGEXP.match(first_ruby_file argv) != nil
- end
-
- def first_ruby_file argv
- argv.find { |e| /.+\.rb$/ =~ e }
+ last_arg = argv[-1]
+ last_arg.match (Regexp.union(SPEC_DIR_REGEXP, SPEC_FILE_REGEXP))
end
def restart_girl_friday

10 comments on commit d5a2302

@aaronjensen

Nice. Any chance of getting a new gem released? :)

@turadg
Collaborator
turadg commented on d5a2302 Dec 22, 2012

I think it was today, in 0.13.2.

@stackedsax

Just tried this and encountered:

/Users/xxx/.rvm/gems/ruby-1.9.3-p327-perf@canncast/gems/activesupport-3.0.11/lib/active_support/whiny_nil.rb:48:in method_missing': undefined methodmatch' for nil:NilClass (NoMethodError)
from /Users/xxx/.rvm/gems/ruby-1.9.3-p327-perf@canncast/gems/zeus-0.13.2/lib/zeus/rails.rb:210:in spec_file?'
from /Users/xxx/.rvm/gems/ruby-1.9.3-p327-perf@canncast/gems/zeus-0.13.2/lib/zeus/rails.rb:185:in
test'

Any ideas on what I am missing?

@turadg
Collaborator
turadg commented on d5a2302 Dec 24, 2012

Sorry, I may have introduced a new bug while fixing the other. This code expects an argument after zeus test. I had only tested with zeus test spec or like zeus test spec/controllers/somecontroller_spec.rb. Does zeus test foo work?

I think these commands could really use some specs to test them out. Informally, how should the command operate? I use Rspec so I'll document what I'd expect there.

With Rspec
zeus test should run the full spec suite
zeus test spec should also run the full spec suite
zeus test spec/dir/some_spec.rb should run just that spec

For each of the above, the spec or specs should be run exactly once. (Another bug right now is that directories are run multiple times, though the first time they don't find any specs and just run an empty dir.)

@stackedsax

Yes, you're right. These two approaches work:

zeus test spec
zeus test spec/dir/some_spec.rb

Only zeus test doesn't work. Glad to know that I did have it working after all.

Your expected behavior on all three options sounds correct to me.

@frodsan
frodsan commented on d5a2302 Jan 7, 2013

indeed. zeus test test feels weird.

@kainosnoema

@turadg I think maybe this change also breaks being able to run an individual test. Maybe it wasn't this commit, but regardless, it's broken in 0.13.2.

0.13.1:

$ zeus rspec spec/models/account_spec.rb --line 25
Run filtered including {:line_number=>25}

Account
  should allow a deleted account code to be reused

Finished in 0.52805 seconds
1 example, 0 failures

0.13.2:

$ zeus rspec spec/models/account_spec.rb --line 25
No tests found on line 25. Valid tests to run:
@turadg
Collaborator
turadg commented on d5a2302 Jan 24, 2013

@kainosnoema yeah, I think this part of the code should be rewritten from scratch. The MiniTest usage isn't working so well either.

I confirm this bug in 0.13.2. Can you submit an new issue for it?

As a work-around until it's fixed, one can use the colon notation:

zeus rspec spec/models/account_spec.rb:25
@kainosnoema

@turadg it looks like issue #234 already covers the bug fairly well (oddly enough 0.13.1 didn't support the colon notation), but I left another comment clarifying the regression.

@turadg
Collaborator
turadg commented on d5a2302 Jan 24, 2013

Thanks!

Please sign in to comment.
Something went wrong with that request. Please try again.