I am working on an app. Rails 5.1.13
If I run a single test, it passes:
rails test test/api/controllers/positions_controller_test.rb
But when I want to run the whole folder, it fails:
rails test test/api/controllers/
Giving this error message: test_should_get_index is already defined in
Running via Spring preloader in process 14518
/home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/testing/declarative.rb:14:in `test': test_should_get_index is already defined in Api::V1::PositionsControllerTest (RuntimeError)
from /home/mato/cuadernogordo/test/api/controllers/teachers_controller_test.rb:11:in `<class:PositionsControllerTest>'
from /home/mato/cuadernogordo/test/api/controllers/teachers_controller_test.rb:3:in `<top (required)>'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `require'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `block in require'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:258:in `load_dependency'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `require'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/test_unit/runner.rb:50:in `block in load_tests'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/test_unit/runner.rb:50:in `each'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/test_unit/runner.rb:50:in `load_tests'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/test_unit/runner.rb:39:in `run'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/commands/test/test_command.rb:38:in `perform'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/command/base.rb:63:in `perform'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/command.rb:44:in `invoke'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/commands.rb:16:in `<top (required)>'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `require'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `block in require'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:258:in `load_dependency'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `require'
from /home/mato/cuadernogordo/bin/rails:9:in `<top (required)>'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:286:in `load'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:286:in `block in load'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:258:in `load_dependency'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:286:in `load'
from /home/mato/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/mato/.rvm/rubi
Each and every test in that folder passes GREEN when I run them individually.
All my controller tests have more or less the same form, like the following:
require 'test_helper'
class Api::V1::PositionsControllerTest < ActionDispatch::IntegrationTest
setup do
@school = schools(:school_one)
@teacher = teachers(:teacher_one)
@course = courses(:course_one)
@position = positions(:position_one)
end
test "should get index" do
get api_v1_positions_url
assert_response :success
end
test "should create position" do
assert_difference('Position.count') do
post "/api/v1/positions", params: { position: { course_id: @course.id, shift: "tarde", status: "activo", teacher_id: @teacher.id, position_type: "titular" }}
end
assert_response 201
assert_response :success
end
test "should show position" do
get api_v1_position_url(@position)
assert_response :success
end
test "should update position" do
patch api_v1_position_url(@position), params: { position: { shift: "tarde", status: @position.status, teacher_id: @position.teacher_id, position_type: "suplente" } }
assert_response :success
end
test "should destroy position" do
assert_difference('Position.count', -1) do
delete api_v1_position_url(@position)
end
assert_response :success
end
end
It seems that you are repeating the class name
Api::V1::PositionsControllerTest
in two different test files:You can see this in the second line of the error:
Modify the teachers_controller_test.rb file so that the class is called
Api::V1::TeachersControllerTest
.