Commit
* `should` syntax has been deprecated in favor of the newer `expect` syntax. The specs were updated to use `expect`. * `treat_symbols_as_metadata_keys_with_true_values` is now the default behavior in RSpec 3 and is no longer a configuration option. * Unused `factories.rb` file was removed
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,6 @@ gem 'colored' | |
gem 'rake' | ||
|
||
group :test do | ||
gem 'rspec' | ||
gem 'rspec', '~> 3.0' | ||
gem 'coveralls', require: false | ||
end |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,28 +6,29 @@ | |
describe '#initialize' do | ||
context 'no params' do | ||
it 'should return the ace of spades' do | ||
subject.suit.should == 'Spades' | ||
subject.rank.should == 'Ace' | ||
new_card = Card.new | ||
expect(new_card.suit).to eq 'Spades' | ||
expect(new_card.rank).to eq 'Ace' | ||
end | ||
end | ||
|
||
context 'params' do | ||
it 'should return the card specified in params' do | ||
new_card = Card.new('Queen', 'Clubs') | ||
new_card.rank.should == 'Queen' | ||
new_card.suit.should == 'Clubs' | ||
expect(new_card.rank).to eq 'Queen' | ||
expect(new_card.suit).to eq 'Clubs' | ||
|
||
new_card = Card.new(3, 'Spades') | ||
new_card.rank.should == 3.to_s | ||
new_card.suit.should == 'Spades' | ||
expect(new_card.rank).to eq '3' | ||
expect(new_card.suit).to eq 'Spades' | ||
|
||
new_card = Card.new('Jack', 'Diamonds') | ||
new_card.rank.should == 'Jack' | ||
new_card.suit.should == 'Diamonds' | ||
expect(new_card.rank).to eq 'Jack' | ||
expect(new_card.suit).to eq 'Diamonds' | ||
|
||
new_card = Card.new(7, 'Hearts') | ||
new_card.rank.should == 7.to_s | ||
new_card.suit.should == 'Hearts' | ||
expect(new_card.rank).to eq '7' | ||
expect(new_card.suit).to eq 'Hearts' | ||
end | ||
end | ||
end | ||
|
@@ -42,20 +43,20 @@ | |
let (:c4) { Card.new(4,'Spades') } | ||
|
||
it 'should reflect the correct rank when compared' do | ||
king.should > queen | ||
king.should > jack | ||
king.should == king | ||
king.should < ace | ||
expect(king).to be > queen | ||
expect(king).to be > jack | ||
expect(king).to eq king | ||
expect(king).to be < ace | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
JoelQ
Author
Contributor
|
||
|
||
jack.should_not > queen | ||
jack.should_not > ace | ||
jack.should < queen | ||
expect(jack).not_to be > queen | ||
expect(jack).not_to be > ace | ||
expect(jack).to be < queen | ||
|
||
ace.should_not < queen | ||
ace.should > c4 | ||
expect(ace).not_to be < queen | ||
expect(ace).to be > c4 | ||
|
||
c2.should < c4 | ||
c2_heart.should == c2 | ||
expect(c2).to be < c4 | ||
expect(c2_heart).to eq c2 | ||
end | ||
end | ||
|
||
|
@@ -64,19 +65,19 @@ | |
let (:king) { Card.new('King', 'Clubs') } | ||
|
||
it 'should return a long rank' do | ||
king.rank.should == 'King' | ||
expect(king.rank).to eq 'King' | ||
end | ||
|
||
it 'should return a short rank' do | ||
king.rank(true).should == 'K' | ||
expect(king.rank(true)).to eq 'K' | ||
end | ||
end | ||
|
||
context 'numeric cards' do | ||
let (:num) { Card.new(10, 'Diamonds') } | ||
|
||
it 'should have the same long and short rank' do | ||
num.rank.should == num.rank(true) | ||
expect(num.rank).to eq num.rank(true) | ||
end | ||
end | ||
end | ||
|
@@ -85,14 +86,15 @@ | |
BORDER_COUNT = 18 # the number of unicode characters on the border | ||
RANKS = [*2..10, 'Jack', 'Queen', 'King', 'Ace'] | ||
|
||
it 'should have the correct number of glyps' do | ||
it 'should have the correct number of glyphs' do | ||
RANKS.each do |rank| | ||
card = Card.new(rank, 'hearts') # rspec doesn't play nice with dark cards | ||
glyph_count = card.to_s.scan(/[^\x00-\x7F]/).count | ||
|
||
if (2..10).include? card.rank.to_i | ||
card.to_s.scan(/[^\x00-\x7F]/).count.should == card.rank.to_i + BORDER_COUNT | ||
expect(glyph_count).to eq card.rank.to_i + BORDER_COUNT | ||
else | ||
card.to_s.scan(/[^\x00-\x7F]/).count.should == 2 + BORDER_COUNT | ||
expect(glyph_count).to eq 2 + BORDER_COUNT | ||
end | ||
end | ||
end | ||
|
@@ -101,7 +103,7 @@ | |
RANKS.each do |rank| | ||
card = Card.new(rank, 'diamonds') | ||
|
||
card.inspect.should == card.short | ||
expect(card.inspect).to eq card.short | ||
end | ||
end | ||
end | ||
|
@@ -112,17 +114,17 @@ | |
runt_card2 = Card.new(11, 'Diamonds') | ||
runt_card3 = Card.new(-6, 'Spades') | ||
|
||
runt_card1.rank.should be_nil | ||
runt_card2.rank.should be_nil | ||
runt_card3.rank.should be_nil | ||
expect(runt_card1.rank).to be_nil | ||
expect(runt_card2.rank).to be_nil | ||
expect(runt_card3.rank).to be_nil | ||
end | ||
|
||
it 'should set a garbage suit to nil' do | ||
runt_card1 = Card.new(7, '') | ||
runt_card2 = Card.new('Ace', 'Garbage') | ||
|
||
runt_card1.suit.should be_nil | ||
runt_card2.suit.should be_nil | ||
expect(runt_card1.suit).to be_nil | ||
expect(runt_card2.suit).to be_nil | ||
end | ||
end | ||
|
||
|
@@ -131,17 +133,17 @@ | |
deck1 = Deck.new | ||
deck2 = Deck.new | ||
deck1.cards.each_with_index do |_, index| | ||
deck1[index].same_as?(deck2[index]).should == true | ||
deck2[index].same_as?(deck1[index]).should == true | ||
expect(deck1[index]).to be_same_as deck2[index] | ||
expect(deck2[index]).to be_same_as deck1[index] | ||
end | ||
end | ||
|
||
it "should return false when compared to different cards" do | ||
deck1 = Deck.new | ||
deck2 = Deck.new | ||
deck1.cards.each_with_index do |_, index| | ||
deck1[index].same_as?(deck2[index-1]).should == false | ||
deck2[index].same_as?(deck1[index-1]).should == false | ||
expect(deck1[index]).not_to be_same_as deck2[index-1] | ||
expect(deck2[index]).not_to be_same_as deck1[index-1] | ||
end | ||
end | ||
end | ||
|
This is the type of code that makes me question if a move to RSpec 3 is an "upgrade."
Look at this:
versus
The latter is much more code, and awkward code as we have to wrap the subject and the value in function calls. But there's something darker in here, and it's in code in this PR like this:
Is it supposed to be
.to eq 4
or.to be 4
? Or should it be.to be object
or.to be_same_as
? Or is it.to be_nil
or.to be nil
? The answers to these are subjective, or it's "insider" stuff... you just have to know to use.to be_nil
or whatever...I'm not against this PR, but part of me wants to "upgrade" the tests by switching to Minitest... tests in that tend to be more simple and consistent.
Stopping my rant now.