Heroku CI test app deletes /spec directory - ruby-on-rails

For some unexplainable reason it appears as though when Heroku CI is building the app in the test environment it deletes my /spec directory.
The error below says, require': cannot load such file -- spec_helper (LoadError)
When I use the Heroku debugger heroku ci:debug --pipeline myapp I see that there is no spec directory. If I run rake or bundle exec rake it gives me the same error that I see in the build UI.
Why could possibly be deleting this directory?
-----> Running test command `rake`...
/app/vendor/ruby-2.3.7/bin/ruby -I/app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/lib:/app/vendor/bundle/ruby/2.3.0/gems/rspec-support-3.7.1/lib /app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
/app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration.rb:1455:in `require': cannot load such file -- spec_helper (LoadError)
from /app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration.rb:1455:in `block in requires='
from /app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration.rb:1455:in `each'
from /app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration.rb:1455:in `requires='
from /app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:112:in `block in process_options_into'
from /app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:111:in `each'
from /app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:111:in `process_options_into'
from /app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:21:in `configure'
from /app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:99:in `setup'
from /app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:86:in `run'
from /app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:71:in `run'
from /app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:45:in `invoke'
from /app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/exe/rspec:4:in `<main>'
/app/vendor/ruby-2.3.7/bin/ruby -I/app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/lib:/app/vendor/bundle/ruby/2.3.0/gems/rspec-support-3.7.1/lib /app/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.7.1/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb failed
-----> test command `rake` failed with exit status 1

In heroku, there's something called a .slugignore file. Someone added the /spec directory to that file, so my CI builds couldn't run.
Don't add your spec directory to .slugignore!

Related

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

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.

LearnRubyTheHardWay Ex#46 - rake aborted, you should require 'minitest/autorun'

I'm on Example 46 of Learn Ruby The Hard Way - Creating a Project Skeleton
Link: http://learnrubythehardway.org/book/ex46.html
So I created all the directories which show up as the following:
skeleton/
NAME.gemspec
Rakefile
data
ext/
tests/
bin/
NAME
doc/
lib/
NAME
NAME.rb
lib/NAME
tests/
test_NAME.rb
I'm in the Skeleton directory in Powershell.
When I run rake test as the tutorial says to I get an error.
Here's the result from Powershell:
PS C:\ruby\learn\projects\skeleton> rake test
C:/RailsInstaller/Ruby2.1.0/bin/ruby.exe -I"lib;tests" -I"C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4
.2/lib" "C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb" "tests/test_NAME
.rb"
Warning: you should require 'minitest/autorun' instead.
Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
From:
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:1:in `<top (required)>'
C:/ruby/learn/projects/skeleton/tests/test_NAME.rb:2:in `<top (required)>'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb:15:in `block in <main>'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb:4:in `select'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb:4:in `<main>'
MiniTest::Unit::TestCase is now Minitest::Test. From C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit/testcase.rb:8:
in `<module:Unit>'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:676:in `<class:Runner>': undefined method `_run_suite' for class
`Test::Unit::Runner' (NameError)
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:261:in `<module:Unit>'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:15:in `<module:Test>'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:7:in `<top (required)>'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/ruby/learn/projects/skeleton/tests/test_NAME.rb:2:in `<top (required)>'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb:15:in `block
in <main>'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb:4:in `select'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb:4:in `<main>'
rake aborted!
Command failed with status (1): [ruby -I"lib;tests" -I"C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/
lib" "C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb" "tests/test_NAME.rb
" ]
Tasks: TOP => test
(See full trace by running task with --trace)
The book says I should get the following response:
Loaded suite tests/test_NAME
Started
.
Finished in 0.000226 seconds.
1 tests, 1 assertions, 0 failures, 0 errors
But instead I get an error. I've search for fixes and using gem install minitest but keep in mind I don't have a gemfile and I don't know if I should for this type of project. If I needed one I assume the tutorial would say so. So what do I do to fix this issue?
You don't need a Gemfile. While you are at skeleton directory, just do:
gem install 'test-unit'
and then from the same directory:
rake test
All tests will pass.
P.S. I just reproduced the whole thing locally following your tutorial and got the error message as yours. Then, I installed the test-unit gem and after that the rake test is working without any error.

Errno::ENOENT: No such file or directory # rb_sysopen - /tmp/

I'm trying to push my app to Heroku, however I'm getting this rather arbitrary error:
Errno::ENOENT: No such file or directory # rb_sysopen -\
/tmp/build_.../config/aws.yml
/tmp/build_.../vendor/bundle/ruby/2.1.0/gems/safe_yaml-1.0.3/lib/safe_yaml.rb:39:in `initialize'
/tmp/build_.../vendor/bundle/ruby/2.1.0/gems/safe_yaml-1.0.3/lib/safe_yaml.rb:39:in `open'
/tmp/build_.../vendor/bundle/ruby/2.1.0/gems/safe_yaml-1.0.3/lib/safe_yaml.rb:39:in `unsafe_load_file'
/tmp/build_.../vendor/bundle/ruby/2.1.0/gems/safe_yaml-1.0.3/lib/safe_yaml.rb:24:in `load_file_with_options'
/tmp/build_.../config/initializers/aws.rb:1:in `<top (required)>'
/tmp/build_.../vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `load'
/tmp/build_.../vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `block in load'
/tmp/build_.../vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:214:in `load_dependency'
/tmp/build_.../vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `load'
/tmp/build_.../vendor/
I have the proper keys in the aws.yml file so I'm not sure why I'm getting this error, also it works fine locally. I've tried removing the /tmp folder and letting Heroku re-generate it which also didn't work. How can I fix it?
Are you sure your config/aws.yml is in the right location and formed properly? Please check for all the references to it on your codebase.
When executing rake tasks the whole rails environment gets loaded. The error you mentioned arises if any file called by initializers or rake tasks doesn't exist or is not formed correctly.

Cannot generate rails command: bundle exec rspec spec/requests

I'm trying to start a second rails project, and for my firstone, rspec worked fine. I copied over the Gemfile to have the same gems, and I have the spec/requests directory in my project file. However, I get this error when I try to execute
C:\Sites\rails_projects\friendapp\app\views\static_pages>bundle exec rspec spec/
requests
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec
/core/configuration.rb:780:in load': cannot load such file -- C:/Sites/rails_pr
ojects/friendapp/app/views/static_pages/spec/requests (LoadError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
1.1/lib/rspec/core/configuration.rb:780:inblock in load_spec_files'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
1.1/lib/rspec/core/configuration.rb:780:in map'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
1.1/lib/rspec/core/configuration.rb:780:inload_spec_files'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
1.1/lib/rspec/core/command_line.rb:22:in run'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
1.1/lib/rspec/core/runner.rb:69:inrun'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
1.1/lib/rspec/core/runner.rb:8:in `block in autorun'
Any clues? Thanks!
It looks like you are not executing bundle exec from the root of the app, but rather from app\views\static_pages:
C:\Sites\rails_projects\friendapp\app\views\static_pages>
The error message says that the file does not exist from that location (static_pages):
C:/Sites/rails_projects/friendapp/app/views/static_pages/spec/requests
Change to the root dir and try again
C:\Sites\rails_projects\friendapp\>bundle exec rspec spec/requests

Setting up teamcity to run rails specs

I'm trying to set up teamcity 5.0.2 to run my rails projects specs (just rake spec)
My setup is:
local git repo
rails app root in
side it (git_root/site_root)
my rake runner settings are:
path to rakefile: site_root/Rakefile
working directory: site_root
rake tasks: spec
attached reporters: rspec
everything else is default.
when I run the build i get the following output:
Checking for changes
Clearing temporary directory: /home/michaelbaldry/Downloads/TeamCity/buildAgent/temp/buildTmp
Checkout directory: /home/michaelbaldry/Downloads/TeamCity/buildAgent/work/65c3a24ba4d13a41
Updating sources: server side checkout...
[Updating sources: server side checkout...] Building incremental patch for VCS root: local projects
[Updating sources: server side checkout...] Repository sources transferred
Starting build process in /home/michaelbaldry/Downloads/TeamCity/buildAgent/work/65c3a24ba4d13a41/site_root
/usr/bin/ruby /home/michaelbaldry/Downloads/TeamCity/buildAgent/plugins/rake-runner/lib/rb/runner/rakerunner.rb --rakefile /home/michaelbaldry/Downloads/TeamCity/buildAgent/work/65c3a24ba4d13a41/site_root/Rakefile spec SPEC_OPTS=--require 'teamcity/spec/runner/formatter/teamcity/formatter' --format Spec::Runner::Formatter::TeamcityFormatter:matrix
(in /home/michaelbaldry/Downloads/TeamCity/buildAgent/work/65c3a24ba4d13a41/site_root)
LoadError: no such file to load -- /home/michaelbaldry/Downloads/TeamCity/buildAgent/work/65c3a24ba4d13a41/site_root/config/../vendor/rails/railties/lib/initializer Stacktrace: /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require' /home/michaelbaldry/Downloads/TeamCity/buildAgent/work/65c3a24ba4d13a41/site_root/config/boot.rb:45:in `load_initializer' /home/michaelbaldry/Downloads/TeamCity/buildAgent/work/65c3a24ba4d13a41/site_root/config/boot.rb:38:in `run' /home/michaelbaldry/Downloads/TeamCity/buildAgent/work/65c3a24ba4d13a41/site_root/config/boot.rb:11:in `boot!' /home/michaelbaldry/Downloads/TeamCity/buildAgent/work/65c3a24ba4d13a41/site_root/config/boot.rb:109 /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require' /home/michaelbaldry/Downloads/TeamCity/buildAgent/work/65c3a24ba4d13a41/site_root/Rakefile:4 /home/michaelbaldry/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in `load' /home/michaelbaldry/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in `raw_load_rakefile' /home/michaelbaldry/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2017:in `load_rakefile' /home/michaelbaldry/Downloads/TeamCity/buildAgent/plugins/rake-runner/lib/rb/runner/rake_ext.rb:621:in `standard_exception_handling' /home/michaelbaldry/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2016:in `load_rakefile' /home/michaelbaldry/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2000:in `run' /home/michaelbaldry/Downloads/TeamCity/buildAgent/plugins/rake-runner/lib/rb/runner/rake_ext.rb:621:in `standard_exception_handling' /home/michaelbaldry/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run' /home/michaelbaldry/Downloads/TeamCity/buildAgent/plugins/rake-runner/lib/rb/runner/rake_ext.rb:357:in `run' /home/michaelbaldry/Downloads/TeamCity/buildAgent/plugins/rake-runner/lib/rb/runner/rakerunner.rb:79 Source: /home/michaelbaldry/Downloads/TeamCity/buildAgent/work/65c3a24ba4d13a41/site_root/Rakefile:4
Rake aborted!
Process exit code: 1
Build finished
any help is very much appreciated!
I had a similar problem. I clicked on the "Build Log" tab and was able to see more detail than the "Overview" tab.
I found a workaround:
gem uninstall test-unit
I can't say I like this solution but at least it worked. The Build Log lead me to google for uninitialized constant Test::Unit::TestResult::TestResultFailureSupport which lead me to another "uninitialized constant error" resource on stackoverflow.com which had the solution.

Resources