0

Estoy trabajando en una app. Rails 5.1.13

Si corro una prueba individual, pasa:

 rails test test/api/controllers/positions_controller_test.rb

Pero cuando quiero ejecutar toda la carpeta, falla:

rails test test/api/controllers/

Dando este mensaje de error: 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

Todas y cada una de las pruebas en esa carpeta pasan con VERDE cuando las ejecuto de forma individual.

Todas mis pruebas de controllers tienen más o menos la misma forma, como la siguiente:

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
0

1 respuesta 1

1

Parece ser que estás repitiendo el nombre de la clase Api::V1::PositionsControllerTest en dos archivos de prueba distintos:

  • positions_controller_test.rb
  • teachers_controller_test.rb

Esto lo puedes ver en la segunda línea del error:

from /home/mato/cuadernogordo/test/api/controllers/teachers_controller_test.rb:11:in `<class:PositionsControllerTest>'

Modifica el archivo teachers_controller_test.rb para que la clase se llame Api::V1::TeachersControllerTest.

2
  • Me quiero matar! pero tenes razón era eso. el 4 sep. 2017 a las 14:04
  • 1
    Muchas gracias por tu ayuda. el 4 sep. 2017 a las 14:22

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.