skip to Main Content

I read this similar post. Inconsistent Rails Test Results.
It only has one response and it doesn’t help me.

I’ve been following along with this new book called Agile Web Development with Rails 6. And the author runs these tests and they don’t work for me.

Here’s what I did.

I created a new rails project using new rails test and then ran rails generate scaffold Product title:string description:text image_url:string price:decimal. This is the command that the author uses.
I then run rails db:migrate RAILS_ENV=test and then am ready to run rails test.

After doing that I get this response in the console.
7 runs, 5 assertions, 0 failures, 3 errors, 0 skips

Here are the errors.

Error:
ProductsControllerTest#test_should_get_index:
ActionView::Template::Error: Permission denied @ rb_file_s_rename - (C:/Users/Client/Desktop/Ruby on Rails/tests/tmp/cache/assets/sprockets/v4.0.0/-T/-TZMQrMJrqe1bey8hRhmqKVmncCU8rFfTfOziZyMSMQ.cache.74410620.20908.613522, C:/Users/Client/Desktop/Ruby on Rails/tests/tmp/cache/assets/sprockets/v4.0.0/-T/-TZMQrMJrqe1bey8hRhmqKVmncCU8rFfTfOziZyMSMQ.cache)
Error:
ProductsControllerTest#test_should_show_product:
ActionView::Template::Error: Permission denied @ rb_file_s_rename - (C:/Users/Client/Desktop/Ruby on Rails/tests/tmp/cache/assets/sprockets/v4.0.0/HM/HMwQEAOlQlZbn_VGqaBmumzU5MudrUMOA7mZ9lf-I3U.cache.73876560.20908.130802, C:/Users/Client/Desktop/Ruby on Rails/tests/tmp/cache/assets/sprockets/v4.0.0/HM/HMwQEAOlQlZbn_VGqaBmumzU5MudrUMOA7mZ9lf-I3U.cache)
    app/views/layouts/application.html.erb:8
    test/controllers/products_controller_test.rb:27:in `block in <class:ProductsControllerTest>'
Error:
ProductsControllerTest#test_should_destroy_product:
ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked
    app/controllers/products_controller.rb:57:in `destroy'
    test/controllers/products_controller_test.rb:43:in `block (2 levels) in <class:ProductsControllerTest>'
    test/controllers/products_controller_test.rb:42:in `block in <class:ProductsControllerTest>'

The inconsistency is that my results vary, here are some of them

7 runs, 7 assertions, 0 failures, 2 errors, 0 skips

7 runs, 4 assertions, 0 failures, 4 errors, 0 skips

7 runs, 8 assertions, 0 failures, 1 errors, 0 skips

And once I had 0 failures and 0 errors. I am absolutely new to Ruby on Rails so any help is appreciated.
Also, I have tried running bundle exec rake db:test:prepare which I read in the post I linked at the top. That didn’t help me.

Edit: I didn’t realize it was important, but my project is actually named tests, not test. So the conflict with the test keyword is not happening. Also, I set up this "test" project after another project named "depot" was initially failing the tests.

My rails version: 6.0.3.2

My Ruby version: 2.6.6p146

Here are the tests for the permission denied errors.
This is excerpted from this file, testcontrollersproducts_controller_test.rb

test "should get index" do
    get products_url
    assert_response :success
end

test "should show product" do
  get product_url(@product)
  assert_response :success
end

My gemfile

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.6'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.1'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3', '~> 1.4'
gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec"

# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

My Gemfile.lock

GIT
  remote: https://github.com/larskanis/sqlite3-ruby
  revision: 1027509079176fcc4088dcc7638101cde617cf16
  branch: add-gemspec
  specs:
    sqlite3 (1.3.13.20180326210955)

GEM
  remote: https://rubygems.org/
  specs:
    actioncable (6.0.3.2)
      actionpack (= 6.0.3.2)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
    actionmailbox (6.0.3.2)
      actionpack (= 6.0.3.2)
      activejob (= 6.0.3.2)
      activerecord (= 6.0.3.2)
      activestorage (= 6.0.3.2)
      activesupport (= 6.0.3.2)
      mail (>= 2.7.1)
    actionmailer (6.0.3.2)
      actionpack (= 6.0.3.2)
      actionview (= 6.0.3.2)
      activejob (= 6.0.3.2)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 2.0)
    actionpack (6.0.3.2)
      actionview (= 6.0.3.2)
      activesupport (= 6.0.3.2)
      rack (~> 2.0, >= 2.0.8)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.2.0)
    actiontext (6.0.3.2)
      actionpack (= 6.0.3.2)
      activerecord (= 6.0.3.2)
      activestorage (= 6.0.3.2)
      activesupport (= 6.0.3.2)
      nokogiri (>= 1.8.5)
    actionview (6.0.3.2)
      activesupport (= 6.0.3.2)
      builder (~> 3.1)
      erubi (~> 1.4)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.1, >= 1.2.0)
    activejob (6.0.3.2)
      activesupport (= 6.0.3.2)
      globalid (>= 0.3.6)
    activemodel (6.0.3.2)
      activesupport (= 6.0.3.2)
    activerecord (6.0.3.2)
      activemodel (= 6.0.3.2)
      activesupport (= 6.0.3.2)
    activestorage (6.0.3.2)
      actionpack (= 6.0.3.2)
      activejob (= 6.0.3.2)
      activerecord (= 6.0.3.2)
      marcel (~> 0.3.1)
    activesupport (6.0.3.2)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 0.7, < 2)
      minitest (~> 5.1)
      tzinfo (~> 1.1)
      zeitwerk (~> 2.2, >= 2.2.2)
    addressable (2.7.0)
      public_suffix (>= 2.0.2, < 5.0)
    bindex (0.8.1)
    bootsnap (1.4.6)
      msgpack (~> 1.0)
    builder (3.2.4)
    byebug (11.1.3)
    capybara (3.33.0)
      addressable
      mini_mime (>= 0.1.3)
      nokogiri (~> 1.8)
      rack (>= 1.6.0)
      rack-test (>= 0.6.3)
      regexp_parser (~> 1.5)
      xpath (~> 3.2)
    childprocess (3.0.0)
    concurrent-ruby (1.1.6)
    crass (1.0.6)
    erubi (1.9.0)
    ffi (1.13.1-x64-mingw32)
    globalid (0.4.2)
      activesupport (>= 4.2.0)
    i18n (1.8.3)
      concurrent-ruby (~> 1.0)
    jbuilder (2.10.0)
      activesupport (>= 5.0.0)
    loofah (2.6.0)
      crass (~> 1.0.2)
      nokogiri (>= 1.5.9)
    mail (2.7.1)
      mini_mime (>= 0.1.1)
    marcel (0.3.3)
      mimemagic (~> 0.3.2)
    method_source (1.0.0)
    mimemagic (0.3.5)
    mini_mime (1.0.2)
    mini_portile2 (2.4.0)
    minitest (5.14.1)
    msgpack (1.3.3-x64-mingw32)
    nio4r (2.5.2)
    nokogiri (1.10.9-x64-mingw32)
      mini_portile2 (~> 2.4.0)
    public_suffix (4.0.5)
    puma (4.3.5)
      nio4r (~> 2.0)
    rack (2.2.3)
    rack-proxy (0.6.5)
      rack
    rack-test (1.1.0)
      rack (>= 1.0, < 3)
    rails (6.0.3.2)
      actioncable (= 6.0.3.2)
      actionmailbox (= 6.0.3.2)
      actionmailer (= 6.0.3.2)
      actionpack (= 6.0.3.2)
      actiontext (= 6.0.3.2)
      actionview (= 6.0.3.2)
      activejob (= 6.0.3.2)
      activemodel (= 6.0.3.2)
      activerecord (= 6.0.3.2)
      activestorage (= 6.0.3.2)
      activesupport (= 6.0.3.2)
      bundler (>= 1.3.0)
      railties (= 6.0.3.2)
      sprockets-rails (>= 2.0.0)
    rails-dom-testing (2.0.3)
      activesupport (>= 4.2.0)
      nokogiri (>= 1.6)
    rails-html-sanitizer (1.3.0)
      loofah (~> 2.3)
    railties (6.0.3.2)
      actionpack (= 6.0.3.2)
      activesupport (= 6.0.3.2)
      method_source
      rake (>= 0.8.7)
      thor (>= 0.20.3, < 2.0)
    rake (13.0.1)
    regexp_parser (1.7.1)
    rubyzip (2.3.0)
    sass-rails (6.0.0)
      sassc-rails (~> 2.1, >= 2.1.1)
    sassc (2.4.0-x64-mingw32)
      ffi (~> 1.9)
    sassc-rails (2.1.2)
      railties (>= 4.0.0)
      sassc (>= 2.0)
      sprockets (> 3.0)
      sprockets-rails
      tilt
    selenium-webdriver (3.142.7)
      childprocess (>= 0.5, < 4.0)
      rubyzip (>= 1.2.2)
    sprockets (4.0.2)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (3.2.1)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)
    thor (1.0.1)
    thread_safe (0.3.6)
    tilt (2.0.10)
    turbolinks (5.2.1)
      turbolinks-source (~> 5.2)
    turbolinks-source (5.2.0)
    tzinfo (1.2.7)
      thread_safe (~> 0.1)
    tzinfo-data (1.2020.1)
      tzinfo (>= 1.0.0)
    web-console (4.0.3)
      actionview (>= 6.0.0)
      activemodel (>= 6.0.0)
      bindex (>= 0.4.0)
      railties (>= 6.0.0)
    webdrivers (4.4.1)
      nokogiri (~> 1.6)
      rubyzip (>= 1.3.0)
      selenium-webdriver (>= 3.0, < 4.0)
    webpacker (4.2.2)
      activesupport (>= 4.2)
      rack-proxy (>= 0.6.1)
      railties (>= 4.2)
    websocket-driver (0.7.2)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.5)
    xpath (3.2.0)
      nokogiri (~> 1.8)
    zeitwerk (2.3.0)

PLATFORMS
  x64-mingw32

DEPENDENCIES
  bootsnap (>= 1.4.2)
  byebug
  capybara (>= 2.15)
  jbuilder (~> 2.7)
  puma (~> 4.1)
  rails (~> 6.0.3, >= 6.0.3.1)
  sass-rails (>= 6)
  selenium-webdriver
  sqlite3!
  turbolinks (~> 5)
  tzinfo-data
  web-console (>= 3.3.0)
  webdrivers
  webpacker (~> 4.0)

RUBY VERSION
   ruby 2.6.6p146

BUNDLED WITH
   1.17.2

2

Answers


  1. Newer versions of Rails do not allow you to make an application called "test" because it can clash with existing modules and classes.

    $ rails new test
    Invalid application name test. Please give a name which does not match one of the reserved rails words: application, destroy, plugin, runner, test
    

    This was added 11 years ago so your copy of Rails might be very out of date. Upgrade Rails and try a different name like test.rails. It Works For Me™.

    Login or Signup to reply.
  2. Having received the same error while running ‘rails test’ on Windows, try running only one test at a time. Worked for me. When running more than one test, it gives the error you show. That’s not a long term solution but maybe it helps you troubleshoot.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search