joncodo / Crib

A crib engine to play the card game crib with AI and a card counter
3 stars 2 forks source link

counter_spec.rb: Code Review. #7

Closed scott-steadman closed 10 years ago

scott-steadman commented 10 years ago

Refactor each before(:each) into separate methods. Reason: So you don't create a bunch of cards that aren't used for most tests.

I believe you can define methods in specs, so here's some sample code:

...
def counter
  @counter ||=  Counter.new([Card.new('J', 'Hearts'),
                            Card.new('2', 'Hearts'),
                            Card.new('3', 'Hearts'),
                            Card.new('4', 'Hearts')],
                           Card.new('5', 'Hearts'))
end

def bad_counter
  @bad_counter =|| Counter.new([Card.new('J', 'Clubs'),
                                Card.new('2', 'Hearts'),
                                Card.new('3', 'Hearts'),
                                Card.new('4', 'Hearts')],
                               Card.new('5', 'Hearts'))
end
...
describe '#right_jack_score' do

  it 'has a score of one with right jack' do
     expect(counter.right_jack_score).to eq 1
  end // it

  it 'has a score of zero with wrong jack' do
    expect(bad_counter.right_jack_score).to eq 0
  end // it

end /// describe #right_jack_score
scott-steadman commented 10 years ago

Get rid of Counter, parameters on inner describes Reason: I believe they're redundant since you're already in a describe Counter block.