I have a Rails project, in which I have a library with specs, lib/foo, which contains a spec folder:
Rails.root
/lib
/foo
/lib
/spec
When I run rspec in Rails root, I would like the foo specs to be ran too. How can I accomplish it?
You could run it like that: rspec spec/ lib/foo/spec
Related
I have a Rails 4.1 project that uses RSpec and Cucumber.
I've recently added fixture_builder.
fixture_builder.rb includes logic to rebuild fixtures any time the file changes.
This works fine for RSpec with require 'fixture_builder' in spec_helper.rb.
However, when running Cucumber tests fixture_builder.rb is not called, so fixtures are not updated if any changes have been made to fixture_builder.rb.
Is there an equivalent config file like spec_helper.rb for Cucumber?
By default, Cucumber loads all *.rb files in the same directory as the feature(s) it's running and all subdirectories of that directory, so you can put your require in any file you want in any of those directories.
The conventional thing to do is to put 'support' code like require in features/support/env.rb, or in another file in features/support if your env.rb gets too big.
The cucumber-rails gem provides a generator that sets up Cucumber to work with Rails. If you haven't already, install the gem and run
rails g cucumber:install
to create features/support/env.rb and the rest of the usual Rails + Cucumber setup.
I am reading ruby and rails tutorial 2nd edition book.
I am facing problem to do dynamic title in title pages.
In this book write done this path "spec/requests/static_pages_spec.rb" and i have not found any spec folder in rails project where it is located ? where can create a static_pages_spec.rb file ?
I am using rails 4.0.2
book link :http://ruby.railstutorial.org/chapters/rails-flavored-ruby#top
Listing 4.4. Updated tests for the Home page’s title.
spec/requests/static_pages_spec.rb
please help me
path "spec/requests/static_pages_spec.rb "
May i create it spec folder in rails root folder ?
Folder spec located in rails root dir.
in Rails you can use Rspec generator or create helper:
add to Gemfile:
gem 'rspec-rails'
run rails generator:
rails g rspec:install
This create folder spec in you project and generate spec_helper.rb
And run rspec or bundle exec rspec.
Folder spec located in rails root directory in your rails app.
in Rails you can use Rspec generator:
following Gem add to Gemfile:
gem 'rspec-rails'
and then run following command on terminal
rails g rspec:install
This create folder spec in you project and generate spec_helper.rb
And run rspec or bundle exec rspec
I just created a mountable engine. The test directory looks somewhat like this:
engine_name
-test
- dummy
- test_helper.rb
- models
-engine_name
-- user_test.rb
etc
I attempted to call 'rspec' -> didn't work. Error message stated it couldn't find the folder 'spec'
I then called 'rspec test' -> it found the directory, but didn't find the test.
Found that rspec looks for *_spec.rb files, so I renamed user_test.rb to user_spec.rb
rspec then found the file, but it said it couldn't find test_helper.rb (since that was required by user_spec.rb).
I have a feeling that this engine's test directory is not designed for rspec. What's the best way to test an engine?
Thanks!
Since you are using rspec, you should use the directory spec instead of test.
The test directory is the default for test unit.
If you run rspec and you have a spec directory it will grab the tests from there.
You need a right spec_helper.rb (test_helper.rb is for test unit). You can see the example of spec_helper.rb in the template from rspec-rails repository.
Then, you should require the spec_helper in the user_spec.rb and just run rspec in the terminal.
No matter what I do, the only tests that run with the rake test command are those in spec/requests. Naturally, I would like to run everything in the spec directory.
I thought getting the gem and installing RSpec would do it, but it seems with these testing libraries that the whole "convention over configuration" thing is turned on its head. There's a hell of a lot of configuration.
I simply want to run all of my tests. How can I do that?
What does your Rakefile look like? You may need to add the following:
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new
Also, check that your spec's filenames all end in _spec.rb.
Just this will do:
bundle exec rspec spec
This must be fired from root directory of application. Here spec is the directory.
I'm using rspec 2.10 with Rails 3.2.1 and have problems with classes not being found.
I have put a class called DbTasks under a dir app/util. Under spec, i've created file util/db_tasks_spec.rb which runs afer i included the line:
require File.join(File.dirname(__FILE__), '../../app/util/db_tasks')
However, rspec now isn't able to find my models. I don't want to have to include these manually. Is there a way to config rspecs paths so everything gets found?