padrino-framework icon indicating copy to clipboard operation
padrino-framework copied to clipboard

More inteligent running of test tasks

Open sshaw opened this issue 8 years ago • 5 comments

Related to #1937 and #1979.

Let me know what you think. I do have some issues with things like this. I just piggybacked on it as poor man's way to avoid two sets of test tasks but, in the case of the DB tasks, why is it needed? Shouldn't this sort of stuff be handled by adding the :environment task as a prerequisite? Anywayz...

For minitest, since the spec format is being used (but also see #1848), I think the task should look for *_spec.rb files and maybe the same goes for bacon, but I left them as is to minimize future impact.

In summary:

This generates test tasks based on the presence of test files and groups tasks by subapp (apps named "app" are ignored).

Previously, everything under the test directory was added as an individual test task, which resulted in N invocations of rake test, often times on directories that had no tests (e.g., support or factory files).

Additional changes, note that these should only affect new projects:

  1. {test,spec}/*.rake is no longer generated. Instead, a modification to the project's Rakefile is made to call PadrinoTasks.use(:xxx). This seems to be more in line with Padrino methodology (starting at v0.11 I think).
  2. The default rake task will be the test (or spec) task.

sshaw avatar Oct 25 '15 19:10 sshaw

This generates test tasks based on the presence of test filesand groups tasks by subapp (apps named "app" are ignored).

Let me elaborate with an example. Here, foo is an app:

/tmp/padrino-rspec >tree spec
spec
├── app
│   ├── controllers
│   │   └── bar_controller_spec.rb
│   └── helpers
│       └── bar_helper_spec.rb
├── foo
│   └── models
│       └── bar_spec.rb
├── models
│   └── sshaw_spec.rb
├── not_a_app
│   ├── bar_spec.rb
│   └── foo.rb
└── spec_helper.rb

7 directories, 7 files
/tmp/padrino-rspec >rake -T spec
=> Executing Rake -T spec ...
rake spec              # Run application test suite
rake spec:controllers  # Run specs in spec/app/controllers
rake spec:foo          # Run all the specs for the foo app
rake spec:foo:models   # Run specs in spec/foo/models
rake spec:helpers      # Run specs in spec/app/helpers
rake spec:models       # Run specs in spec/models
rake spec:not_a_app    # Run specs in spec/not_a_app

sshaw avatar Oct 25 '15 22:10 sshaw

I love your approach. Thanks for the patch!

namusyaka avatar Jan 07 '16 13:01 namusyaka

It looks like it conflicts with this feature request: #765

ujifgc avatar May 04 '16 08:05 ujifgc

It looks like it conflicts with this feature request: #765

What do you want to do? Has that feature been implemented? If not I say we go with this until the other feature is ready. Current test tasks are broken and can be annoying (see #1937 and #1979). This will fix it.

sshaw avatar May 05 '16 02:05 sshaw

Is there any interest in merging all or part of this? #765 has not been merged and current test behavior has two issues: one small yet annoying and the other somewhat big.

  1. rake -T shows what are essentially noop tasks: spec:factories, spec:support, etc...
  2. Because rake spec (or rake test) uses the subfolder based tasks as dependencies, a failing spec prevents all other specs from running.

sshaw avatar Feb 12 '17 17:02 sshaw