New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems customizing spec directory structure #600
Comments
Hey Alex, I like the approach you're taking...it's actually the way I've been doing it on several projects recently, although I haven't tried it on a rails project yet. The integration rspec-rails provides for the various spec types is based on modules that get included example groups based on the convention of which directory the spec files are in. Have a look at the example folder to see all the modules that get included each spec type. example.rb wires it all up based on the You'll need to do this wiring yourself since you're outside of the "normal" conventions for rspec-rails. You can either include the modules manually in each example group, use metadata to tag the example groups with their type, and include based on the type, or use a similar file_path convention approach as rspec-rails does. |
Is there anything actionable that RSpec itself can do here? :) |
Thanks for your help Myron, still haven't tried the solution you proposed but will close the issue, and as soon as I get it done will post it here for feedback. |
Hi, I'm trying to do the same thing and poking around the docs it seems you can add a https://www.relishapp.com/rspec/rspec-rails/v/2-12/docs/controller-specs I've successfully made this change in a Rails app. It looks like the change was probably made in 2.4 at least by going on the documentation. The top of each file looks like:
My directory structure is:
|
Hi guys,
I'm trying to come up with a different testing structure for my project where I can define three types of specs (unit, integration and acceptance), so under spec directory I created these 3 subdirectories. The goal is to run my specs as fast as possible, each type with its own spec_helper.rb file, with the minimum necessary to run the specs for that type. And also to be able to run something like rake spec:unit, rake spec:integration or rake spec:acceptance. So with this goal, my directory structure looks like the following:
spec
|=> unit (tests only domain logic, no persistence or integration points)
|=> integration (tests the integration with persistence mechanisms, message bus, etc.)
|=> acceptance (tests user interaction, with capybara)
Inside the unit directory I created the default subdirectories (models, controllers, helpers, views, etc.) with the proper specs inside each of them. For example, I created a spec called application_controller_spec.rb, inside spec/unit/controllers. The problem is when I try to run this spec, by executing the command (rspec spec/unit/controllers/application_controller_spec.rb) I get the following error:
undefined method
controller' for #<Class:0x007f8f0a6e3610> (NoMethodError) from /Users/amartins/.rvm/gems/ruby-1.9.3-p194@receitas/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:202:in
module_eval'from /Users/amartins/.rvm/gems/ruby-1.9.3-p194@receitas/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:202:in
subclass' from /Users/amartins/.rvm/gems/ruby-1.9.3-p194@receitas/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:187:in
describe'from /Users/amartins/Development/projects/receitas/spec/unit/controllers/application_controller_spec.rb:49:in
block in <top (required)>' from /Users/amartins/.rvm/gems/ruby-1.9.3-p194@receitas/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:202:in
module_eval'from /Users/amartins/.rvm/gems/ruby-1.9.3-p194@receitas/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:202:in
subclass' from /Users/amartins/.rvm/gems/ruby-1.9.3-p194@receitas/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:187:in
describe'from /Users/amartins/.rvm/gems/ruby-1.9.3-p194@receitas/gems/rspec-core-2.8.0/lib/rspec/core/dsl.rb:18:in
describe' from /Users/amartins/Development/projects/receitas/spec/unit/controllers/application_controller_spec.rb:5:in
<top (required)>'from /Users/amartins/.rvm/gems/ruby-1.9.3-p194@receitas/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:699:in
load' from /Users/amartins/.rvm/gems/ruby-1.9.3-p194@receitas/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:699:in
block in load_spec_files'from /Users/amartins/.rvm/gems/ruby-1.9.3-p194@receitas/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:699:in
map' from /Users/amartins/.rvm/gems/ruby-1.9.3-p194@receitas/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:699:in
load_spec_files'from /Users/amartins/.rvm/gems/ruby-1.9.3-p194@receitas/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in
run' from /Users/amartins/.rvm/gems/ruby-1.9.3-p194@receitas/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in
run_in_process'from /Users/amartins/.rvm/gems/ruby-1.9.3-p194@receitas/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in
run' from /Users/amartins/.rvm/gems/ruby-1.9.3-p194@receitas/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in
block in autorun'It doesn't find the reference to the controller method, from rspec-rails, and also any other method like 'get', 'put', 'response', etc.
I tried to follow the piece of code where the error is happening, but couldn't find the solution. Is there a configuration I need to do, to be able to customize my directory structure?
Thanks!
~Alex
The text was updated successfully, but these errors were encountered: