app/controllers/limericks_controller.rb
file to add a logic bug such that, in the index
method, the call to Limerick.all.reverse_order
is replaced with a call to Limerick.take(1)
(which returns a collection of Limerick
objects containing only 1 limerick).class LimericksController < ApplicationController
before_action :authenticate_user!, except: [:index]
before_action :require_permission, except: [:index, :new, :create]
def index
@limericks = Limerick.take(1)
render :index
end
...
Limerick
test fixtures, but our app will now retrieve only 1 of them (due to the take(1)
call).
LimericksControllerTest#should_get_index
test case, the assertion assert_select 'div.card', limericks_size
should now fail because the number of div.card
elements printed will be 1, whereas the limericks_size
value will be 2.rails test -v
Running 1 tests in a single process (parallelization threshold is 50)
Run options: -v --seed 31239
# Running:
LimericksControllerTest#test_should_get_index = 2.24 s = F
Failure:
LimericksControllerTest#test_should_get_index [test/controllers/limericks_controller_test.rb:8]:
Expected exactly 2 elements matching "div.card", found 1..
Expected: 2
Actual: 1
rails test test/controllers/limericks_controller_test.rb:4
Finished in 2.243783s, 0.4457 runs/s, 0.8914 assertions/s.
1 runs, 2 assertions, 1 failures, 0 errors, 0 skips
assert_select 'div.card', limericks_size
did indeed fail.
LimericksControllerTest#test_should_get_index
test case on line 8 of the limericks_controller_test.rb
file (where the assert_select
call is found).Expected exactly 2 elements matching "div.card", found 1..
”.