No command "rails test" in my Ruby-on-Rails application - ruby-on-rails

I've recently joined a team on a Ruby-on-Rails application, and I try to audit the tests. There were no tests, so I decided to implement them in the app.
After seeing around what was there, I have seen there were no command to run the tests available. I ran the following command:
rails --tasks
In the output, there is no command such as rails test, rails test:system. Surprisingly, I can run the command rails test with success. But the command rails test:system --trace fails with following output:
rails aborted!
Don't know how to build task 'test:system' (see --tasks)
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task_manager.rb:59:in `[]'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:159:in `invoke_task'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `block (2 levels) in top_level'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `each'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `block in top_level'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:125:in `run_with_threads'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:110:in `top_level'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.2.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:186:in `standard_exception_handling'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.2.1/lib/rails/commands/rake/rake_command.rb:20:in `perform'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.2.1/lib/rails/command.rb:48:in `invoke'
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.2.1/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:9:in `require'
bin/rails:9:in `<main>'
I have tried running the command in a freshly created app, and I can see the available commands rails test and rails test:system.
rails --tasks
Any idea why the command rails test:system fails? Thanks.
Ruby version: 2.3.3
Rails version: 5.2.0
EDIT:
I'm using MiniTest

To run all specs in a single go:
rspec
To execute a specific test file:
rspec <path to the file> # rspec spec/controllers/mytest_spec.rb
Use --format documentation for a formatted output.
Prepend bundle exec if rspec throws a dependency error.

Related

How to use the attach gem in rails 5

My environment:
Ruby 2.4.1
Rails 5.1.4
I am trying to use the attach gem, written by the person who also wrote this article https://atech.blog/atech/file-attachments-in-rails-tutorial.
When I run the bundle install it installs attach gem, version 1.0.2
Then when I try to run the rake command I get an error saying it does not know how to build the task.
rake attach:install:migrations --trace
rake aborted!
Don't know how to build task 'attach:install:migrations' (see --tasks)
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/task_manager.rb:59:in `[]'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:159:in `invoke_task'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:116:in `each'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:116:in `block in top_level'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:125:in `run_with_threads'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:110:in `top_level'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:83:in `block in run'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:186:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/lib/rake/application.rb:80:in `run'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.4.1/bin/rake:23:in `load'
/usr/local/rvm/gems/ruby-2.4.1/bin/rake:23:in `<main>'
/usr/local/rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `<main>'
Any ideas on what the error is? I am wondering if I am missing a required gem to make it work. The link to the attach documentation is https://github.com/adamcooke/attach
There are no rake tasks defined in this repo.
After you run bundle install, you can get a list of rake tasks by running rake -P (rake -T shows tasks with descriptions). You'll see that attach:install:migrations is not there.
Why not try using paperclip?

Rake tasks work locally but not on Heroku

I have a rake task that loads data into tables of my database. I made changes recently to my schema, and migrating them to heroku appears to have worked fine. However, when I run my rake task, I get the following error message:
Don't know how to build task 'import_foursquare_response:create_records'
and a less than helpful stack trace:
heroku run rake import_foursquare_response:create_records --trace
Your version of git is 2.2.0. Which has serious security vulnerabilities.
More information here: https://blog.heroku.com/archives/2014/12/23/update_your_git_clients_on_windows_and_os_x
Running `rake import_foursquare_response:create_records --trace` attached to terminal... up, run.5353
rake aborted!
Don't know how to build task 'import_foursquare_response:create_records'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/task_manager.rb:62:in `[]'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:149:in `invoke_task'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_level'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/bin/rake:23:in `load'
/app/vendor/bundle/ruby/2.0.0/bin/rake:23:in `<main>'
Most of the questions I've seen have pointed to syntax errors in the way people had written the actual rake task, but I can't see any problems there.
require 'four_square'
namespace :import_foursquare_response do
include FourSquare
desc "Load database with results of API calls"
task :create_records => :environment do
puts "Loading database..."
Any help is much appreciated. No data makes my app useless.
I am guessing it is just because heroku does not do any disk writing with rake tasks, please see below:
Src: https://devcenter.heroku.com/articles/rake

Rake aborted: Don't know how to migrate after rails install

I'm trying to go from a newly installed version of rails. To creating a project and migrating the database based off of the model that I scaffolded using rails. And I'm running into a Don't know how to build task 'db::migrate' error.
Commands I ran..
Removing all gems:
for i in 'gem list --no-versions'; do gem uninstall -aIx $i; done
Installing rails and creating new project
sudo gem install rails
rails new test-api
rails generate controller user index
rails generate model user name:string
So that is my setup..
Then I did the method to migrate my database:
rake db::migrate
And here was my output:
rake db::migrate
rake aborted!
Don't know how to build task 'db::migrate'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `block in load'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
/Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/command_wrapper.rb:40:in `call'
/Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/application.rb:180:in `block in serve'
/Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/application.rb:153:in `fork'
/Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/application.rb:153:in `serve'
/Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/application.rb:128:in `block in run'
/Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/application.rb:122:in `loop'
/Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/application.rb:122:in `run'
/Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/application/boot.rb:18:in `<top (required)>'
-e:1:in `<main>'
(See full trace by running task with --trace)
I found a solution. Had I just refreshed my page on my server I would have found this:
Which gave me the answer to just run this command:
bin/rake db:migrate RAILS_ENV=development

RVM setup, rake::doc, and "rake aborted! no such file to load -- initializer"

So I've wanted to install RVM for a while on OSX. I finally got it working after figuring out I had to download the latest XCode. I installed ruby 1.9.2 and used these commands to create a new gemset in rvm:
rvm gemset create rails235
rvm 1.9.2#rails235
gem install rails -v 2.3.5
Then I went into one of my old apps that used rails 2.3.5 and tried to run some rakes and any rake I run I seem to get this error:
rake aborted!
no such file to load -- initializer
Also, semi related, right now I'm trying to get rdoc setup. I've never used before and I'm typing in "rake doc::app" and I'm getting that same error.
The full rake with --trace is this:
$ rake doc::app
rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+)
rake aborted!
Don't know how to build task 'doc::app'
(See full trace by running task with --trace)
brenton-wejrowskis-macbook-pro-2:bizzark wejrowski$ rake doc::app --trace
rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+)
rake aborted!
Don't know how to build task 'doc::app'
/Users/wejrowski/.rvm/gems/ruby-1.9.2-p180#global/gems/rake-0.9.2/lib/rake/task_manager.rb:49:in `[]'
/Users/wejrowski/.rvm/gems/ruby-1.9.2-p180#global/gems/rake-0.9.2/lib/rake/application.rb:111:in `invoke_task'
/Users/wejrowski/.rvm/gems/ruby-1.9.2-p180#global/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level'
/Users/wejrowski/.rvm/gems/ruby-1.9.2-p180#global/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/Users/wejrowski/.rvm/gems/ruby-1.9.2-p180#global/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level'
/Users/wejrowski/.rvm/gems/ruby-1.9.2-p180#global/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/wejrowski/.rvm/gems/ruby-1.9.2-p180#global/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Users/wejrowski/.rvm/gems/ruby-1.9.2-p180#global/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run'
/Users/wejrowski/.rvm/gems/ruby-1.9.2-p180#global/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/wejrowski/.rvm/gems/ruby-1.9.2-p180#global/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Users/wejrowski/.rvm/gems/ruby-1.9.2-p180#global/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/Users/wejrowski/.rvm/gems/ruby-1.9.2-p180#global/bin/rake:19:in `load'
/Users/wejrowski/.rvm/gems/ruby-1.9.2-p180#global/bin/rake:19:in `<main>'
No idea what to do next!
Your rake doc::app error is most probably due to the fact that rake tasks only use a single colon (":") to separate namespaces and task names. Try running rake doc:app instead.

Cucumber rake cucumber:ok - errors

I am getting errors when I run: rake cucumber:ok
Can you please tell me how to fix the following error?
Gem versions I am using:
rails Rails 3.0.8.rc4
rspec 2.6.3
cucumber 0.10.3
Errors when I run: rake cucumber:ok
[ticketee (master)]$ rake cucumber:ok
/Users/duser/.rvm/rubies/ruby-1.9.2-p180/bin/ruby -S bundle exec cucumber --profile default
Using the default profile...
features/creating_projects.feature: Lexing error on line 12: '%%_FEATURE_END_%%'. See http://wiki.github.com/cucumber/gherkin/lexingerror for more information. (Gherkin::Lexer::LexingError)
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/gherkin-2.3.10/lib/gherkin/lexer/i18n_lexer.rb:23:in `scan'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/gherkin-2.3.10/lib/gherkin/lexer/i18n_lexer.rb:23:in `scan'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/gherkin-2.3.10/lib/gherkin/parser/parser.rb:31:in `parse'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/feature_file.rb:37:in `parse'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/runtime/features_loader.rb:28:in `block in load'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/runtime/features_loader.rb:26:in `each'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/runtime/features_loader.rb:26:in `load'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/runtime/features_loader.rb:14:in `features'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/runtime.rb:132:in `features'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/runtime.rb:45:in `run!'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/cli/main.rb:43:in `execute!'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/cli/main.rb:20:in `execute'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/bin/cucumber:14:in `<top (required)>'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/bin/cucumber:19:in `load'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/bin/cucumber:19:in `<main>'
rake aborted!
Command failed with status (1): [/Users/duser/.rvm/rubies/ruby-1.9.2-p18...]
Tasks: TOP => cucumber:ok
(See full trace by running task with --trace)
[ticketee (master)]$
Contents of features/creating_projects.feature
Feature: Creating projects
In order to have projects to assign tickets to
As a user I want to create them easily
Scenarios: Creating a project
Given I am on the homepage
When I follow "New Project"
And I fill in "Name" with "Text Mate 2"
And I press "Create Project"
Then I should see "Project has been created"
I figured out the problem:
In the features/creating_projects.feature file, I had "Scenarios:", and it should be "Scenario:". This is the reason for the errors.
You have a lexing error on line 12 of features/creating_projects.feature and its most likely at the end of the feature definition. Are you using the correct syntax in the file?

Resources