Capybara + RSpec, spec/features dir being ignored by the rspec . command? - ruby

I'm using the new Capybara DSL with rspec following the short guideline located here
And the tests added to the spec/features directory run well alone, ie.
rails_project$ rspec spec/features/my_first_feature.rb
However the spec/features directory is totally ignored when I try to run the tests for the entire spec/ directory like this:
rails_project$ rspec .
There is no mention in the guide about how to include this directory (or other directory) to accomplish this inclusion that I desire. I really need this for continuous integration of my project.
Can anybody please tell me how to do it?
Thanks!

You need to make sure all of your specs end in_spec.rb.
Change the filename to spec/features/my_first_feature_spec.rb
This is how I do it:
rspec spec
You may also want to use guard-rspec, which gives you better control.

Related

How to use multiple rspec_helpers

We are experimenting with adding integration tests with rspec into our workflow, and are experimenting the following folder structure:
.
├── spec #unit tests
├── spec-integration #e2e tests
When I run the e2e tests with bundle exec rspec SPECS=spec-integration, the --require spec_helper from .rspec automatically goes to spec/spec_helper. This makes sense and expected, but we don't want to use the spec_helper from the unit tests, we want to use another one for integration tests.
How do I tell rspec to go to spec-integration/spec_handler instead of spec/spec_handler as a default?
(Edit/PS: Comments from a folder architecture or suggestions on a better way to design this are also welcome, as we are pretty new to the Ruby ecosystem)
Thanks!
You can override that by specifying --options command line flag. (ref)
bundle exec rspec --default-path spec-integration --options spec_handler
Also, when you use --default-path, you can have a spec-integration/spec_helper.rb and it will use that(because of --require spec_helper in .rspec).
(This is not working for me on rspec 3.9 though - bundle exec rspec SPECS=spec-integration.)
Coming to the folder structure part, I would keep integration specs in a sub-folder inside spec. Both unit and integration specs can have their own helper files and spec/spec_helper can have common configuration.

Ruby - rspec how to include specs in root of project?

rspec always finds files in the spec/ directory tree.
How can I have it also find files that are in the root of the project (the one that contains the spec/ folder iself.
For example if I have a small project with only two tests, any folders may essentially be unneeded overhead given a minimalist approach. Or if you only have one type of test and would only create one folder it may not (or may) be worth creating that one folder or just omitting it altogether. The value it adds of course is immediate description of what type of tests exist, even if only one type exist.
Spec supports a --default-path option, and you can put a default set of command-line options into an .rspec file. That is, you can create a .rspec file in your project root directory containing
--default-path .
My experience has generally been that rspec tests are almost always in a spec directory; I would be a little surprised to see them in a top-level directory. This in particular mirrors the standard gem filesystem layout which puts all library code into a lib directory and tests in a parallel spec directory.
One approach:
# File: spec_helper.rb Add the following at the top:
Dir.glob(File.expand_path("../../*_spec.rb", __FILE__)).each do |file|
require file
end
This will include files at the root to the ones already being included in spec/

Rspec multiple spec folders

Im currently building a project using Rspec in which I sepparated in two different folders with domain code and infrastructure code. Both folders have their own specs in a spec folder. The domain/spec folder is the one containing the spec_helper.rb file, thats required from the tests inside the other folder infrastructure/spec
I'd like to know how to have a spec folder in the root of the project, including the spec_helper file and also tests, and being able to run all the tests with just one command (right now I do it running rspec domain/ infrastructure/)
RSpec is designed to work with all tests in one folder. By default, this folder is called spec/, but you can use a different name with the --default-path option.
So, your options as I see it are:
Edit the source code of rspec-core to let that configuration support multiple directories. Hopefully your PR will be approved and merged.
Or, write a simple wrapper script that runs rspec against both directories. For example, you could alias rspecs='rspec domain/ infrastructure/'.
Or (what I would recommend!), you could just restructure your tests slightly to use spec/domain/ and spec/infrastructure/ folders -- and then everything will just work, by convention, out of the box.

Configure Mocha Test Runner in Bamboo

I've configured and am executing mocha tests in WebStorm, so I know the module is working properly. But I can't seem to make it run from a Bamboo task. The task runs with Success but there are 0 tests executed.
This is my configuration atm:
app/ is my working dir. Tried also with app/node_modules/mocha/bin/ and other possibilities. I am not sure which exactly is the Mocha executable of all the mocha named files in the module...
Or maybe the problem lies in the tests dir? I've got test files, respectively in app/test/unit/models/ and app/test/unit/services/. But in WebStorm I configured it with the general test dir - just /app/test. Configuring the Mocha task in Bamboo with the specific test folders did not yield result...
I believe the problem comes from wrong directory configurations in the task, but I've tried writing whatever paths already and I've got no idea what's missing or wrong...
I noticed from your screenshot that the "Parse test results produced by this task" box isn't checked. This is what tells Bamboo to parse the output of the tests that you run.

override --fail-fast in rspec

I run specs in my local machine and in a CI server. In the first case I want specs to fail fast, and in the other I want run all of them. I've set --fail-fast in my .rspec file. How can I override it on the CI server? I run there RSpec using rake spec and I set SPEC_OPTS env variable.
The simplest answer is to remove .rspec from your repo. It is used only by you and any other contributor don't need to see that you are using NyanCat to see how your test's are doing.
You can add a .rspec file in your home directory so that the settings only apply to your local machine, and then the .rspec in the project directory will override any settings there.
--no-fail-fast has since been added.
https://relishapp.com/rspec/rspec-core/docs/command-line/fail-fast-option#using-%60--no-fail-fast%60

Resources