Rails - How can I run cucumber tests only? - ruby-on-rails

I can run all models with rake:models
Any option to do that that for cucumber tests instead of just rake and running all tests at all levels?
I tried:
$ rake spec:cucumber
rake aborted!
Don't know how to build task 'spec:cucumber'

You should be able to just run rake cucumber
A quick output of rake -T shows:
rake cucumber # Alias for cucumber:ok
rake cucumber:all # Run all features
rake cucumber:ok # Run features that should pass
rake cucumber:rerun # Record failing features and run only them if any exist
rake cucumber:wip # Run features that are being worked on

Related

Why is `rake -T` run with RAILS_ENV test?

Problem
Some rake tasks provided by gems did not show up with rake -T or rake -T -A (rake > 10).
Discovery
Gems listed only in the :development group are not loaded when rake -T is run. I found that this is likely because ENV['RAILS_ENV'] is being set to test when running rake -T.
However, rake tasks are invoked in the development environment. Why is rake -T setting the RAILS_ENV to test?

How to 'rake spec' one directory, e.g. models?

I can rake spec and all specs run.
However trying to run specs for one directory, as in
rake spec/models/ or rake spec/models/*.rb
does not provide any output or errors.
One option is that I can do
rspec spec/models/*.rb
or
rspec spec/models/
but I was wondering if I could stay within Rake.
Try rake spec:models instead of rake spec/models. Run rake -T | grep spec to see all the available rake spec tasks.
UPDATE: Running your specs through rake spec may be slower than running them through rspec spec, said by the rspec-rails guys. Read de installation section of rspec-rails.
Use SPEC env. variable:
rake spec SPEC=spec/models

Difference between adding RAILS_ENV before or after a rake task

What's the difference between adding a RAILS_ENV before or after a rake task? Here are samples from my staging environments:
Adding RAILS_ENV after rake task.
This raised an error, and the reason for this is accepting development environment as by default and not taking devutility as the environment.
$bundle exec rake -T RAILS_ENV=devutility
$rake aborted!
$cannot load such file -- rack/bug
Adding RAILS_ENV before rake task
This works and lists all the rake task available.
$RAILS_ENV=devutility bundle exec rake -T
rake about # List versions of all Rails frameworks and the environment
rake assets:clean # Remove compiled assets
rake assets:precompile # Compile all the assets named in config.assets.precompile
rake bourbon:install[sass_path] # Move files to the Rails assets directory
rake ci # Continuous Integration build (simplecov-rcov and deploy)
rake cucumber # Alias for cucumber:ok
rake cucumber:all # Run all features
rake cucumber:ok # Run features that should pass
rake cucumber:rerun # Record failing features and run only them if any exist
rake cucumber:wip # Run features that are being worked on
rake db:create # Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)
rake db:data:dump ....................
..............
RAILS_ENV is an environment variable that needs to be available before running your rake task.
When you do:
RAILS_ENV=devutility bundle exec rake -T
It has the same affect as:
export RAILS_ENV=devutility
bundle exec rake -T
RAILS_ENV is not an argument to rake as it may appear, it's part of the environment available to Ruby though it's ENV constant.

Why is rake db:migrate:reset not listed in rake -T?

Why are some rake tasks not listed by rake -T? Like db:migrate:reset? I can execute it without a problem, but why is it not listed there? Is there a way to get a real full list of rake tasks?
% rake -T
(in /home/zeus/projects/my_project)
rake about # List versions of all Rails frameworks and the environment
rake db:create # Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)
rake db:drop # Drops the database for the current Rails.env (use db:drop:all to drop all databases)
rake db:fixtures:load # Load fixtures into the current environment's database.
rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false).
rake db:migrate:status # Display status of migrations
rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n).
rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR
rake db:schema:load # Load a schema.rb file into the database
rake db:seed # Load the seed data from db/seeds.rb
rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)
rake db:structure:dump # Dump the database structure to an SQL file
rake db:version # Retrieves the current schema version number
rake doc:app # Generate docs for the app -- also availble doc:rails, doc:guides, doc:plugins (options: TEMPLATE=/rdoc-template.rb, TITLE="Custom Title")
rake erd # Generate an Entity-Relationship Diagram based on your models
rake log:clear # Truncates all *.log files in log/ to zero bytes
rake middleware # Prints out your Rack middleware stack
rake notes # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)
rake notes:custom # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM
rake rails:template # Applies the template supplied by LOCATION=/path/to/template
rake rails:update # Update both configs and public/javascripts from Rails (or use just update:javascripts or update:configs)
rake routes # Print out all defined routes in match order, with names.
rake secret # Generate a crytographically secure secret key (this is typically used to generate a secret for cookie sessions).
rake spec # Run all specs in spec directory (excluding plugin specs)
rake spec:acceptance # Run the code examples in spec/acceptance
rake spec:controllers # Run the code examples in spec/controllers
rake spec:helpers # Run the code examples in spec/helpers
rake spec:lib # Run the code examples in spec/lib
rake spec:mailers # Run the code examples in spec/mailers
rake spec:models # Run the code examples in spec/models
rake spec:rcov # Run all specs with rcov
rake spec:requests # Run the code examples in spec/requests
rake spec:routing # Run the code examples in spec/routing
rake spec:views # Run the code examples in spec/views
rake stats # Report code statistics (KLOCs, etc) from the application
rake test # Runs test:units, test:functionals, test:integration together (also available: test:benchmark, test:profile, test:plugins)
rake test:recent # Run tests for recenttest:prepare / Test recent changes
rake test:uncommitted # Run tests for uncommittedtest:prepare / Test changes since last checkin (only Subversion and Git)
rake time:zones:all # Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter, e.g., OFFSET=-6
rake tmp:clear # Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:sockets:clear)
rake tmp:create # Creates tmp directories for sessions, cache, sockets, and pids
Tasks that don't have a description will not show up.
EDIT: Looks like DHH removed the description from Rails 3 for a few tasks to 'cut down on noise'. rake db:setup has a note about db:reset though.
http://github.com/rails/rails/commit/983815632cc1d316c7c803a47be28f1abe6698fb
You can also use rake db -T -A to show all tasks, even uncommented ones. For reference these switches are doing the following:
-T, --tasks [PATTERN] Display the tasks (matching optional PATTERN) with
descriptions, then exit.
-A, --all Show all tasks, even uncommented ones (in combination
with -T or -D)
You can use rake -P | grep rake to show the names of all Rake tasks.
As a follow up to Thomas Obermüller's answer, since the -T flag takes a positional argument, to get just the 'db' namespace tasks (at least with rake 10.0.3) you need to do: rake -T db -A
On this WIKI - Ruby on Rails/ActiveRecord/Migrations you can find some more information.
For windows user, you do this rake -P | find "rake"

missing rake tasks?

I have ran gem install rails and am running 2.3.4
but i am missing some rake tasks like 'db' and 'gems'
if i run rake -T i get the following tasks. How can i get all the others ?
rake apache2 # Build Apache 2 module
rake clean # Remove compiled files
rake clobber # Remove all generated
files
rake default # Build everything
rake doc # Generate all documentation
rake doxygen # Generate Doxygen C++
API documentation if ...
rake doxygen:clobber # Remove
generated Doxygen C++ API documenta...
rake doxygen:force # Force generation
of Doxygen C++ API docume...
rake fakeroot # Create a fakeroot,
useful for building nat...
rake nginx # Build Nginx helper server
rake package # Build all the packages
rake package:clean # Remove package
products
rake package:debian # Create a Debian
package
rake package:force # Force a rebuild
of the package files
rake package:gem # Build the gem file
passenger-2.2.4.gem
rake rdoc # Build the rdoc HTML Files
rake rdoc:clobber # Remove rdoc
products
rake rdoc:force # Force a rebuild of
the RDOC files
rake sloccount # Run 'sloccount' to
see how much code Passe...
rake test # Run all unit tests and
integration tests
rake test:cxx # Run unit tests for the
Apache 2 and Nginx ...
rake test:integration # Run all
integration tests
rake test:integration:apache2 # Run
Apache 2 integration tests
rake test:integration:nginx # Run
Nginx integration tests
rake test:oxt # Run unit tests for the
OXT library
rake test:rcov # Run coverage tests
for the Ruby libraries
rake test:restart # Run the 'restart'
integration test infinit...
rake test:ruby
If anyone knows why this has happened, how i can fix it or anything else that could help, please let me know
thanks alot
rick
seems like the rake tasks for mod_rails.
To run the tests for rails go to rails folder.

Resources