jimweirich / rspec-given

Given/When/Then keywords for RSpec Specifications
https://github.com/jimweirich/rspec-given
MIT License
654 stars 61 forks source link

RSpec Given should show the invariant that failed, not the Then that triggered the invariant #15

Closed jimweirich closed 11 years ago

jimweirich commented 11 years ago

For example, in the following error message:

  1) TicTacToe when the player goes first in position 2 
     Failure/Error: Then { (1..9).any? { |i| game.position(i) == "O" } }
       Then expression failed at /Users/jim/pgm/ruby/katas/tictactoe/ttt_spec.rb:11
       expected: "O"
       to equal: "X"
         false   <- game.position(players_choice) == "X"
         "O"     <- game.position(players_choice)
         2       <- players_choice
         #<TicTacToe:0x007ff0aa14fe90 @layout=[nil, "O", nil, nil, nil, nil, nil, nil, nil]>
                 <- game
     # ./ttt_spec.rb:20:in `block in Then'

Line 11 is the invariant: Invariant { game.position(players_choice) == 'X' } that is failing. And you can see that RSpec/Given is correctly breaking down the invariant expression. However, the Failure/Error: line shows the triggering Then clause, and not the invariant clause.

This should be changed (if possible).

jimweirich commented 11 years ago

I couldn't change the actual Failure/Error line in the error message, that is formatted by RSpec and not generally under my control. However, if the error is either an And or an Invariant clause, I did add the actual source line of the failing clause to the error message so that the expression breakdown can be seen in context.