From b3888d02c735c252341e28f253d8e5eac4aa928a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Quenneville?= Date: Sat, 26 Jul 2014 01:27:24 -0400 Subject: [PATCH] Upgrade to RSpec 3 * `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 --- Gemfile | 2 +- spec/factory.rb | 10 ----- spec/rubycards/card_spec.rb | 76 ++++++++++++++++++----------------- spec/rubycards/deck_spec.rb | 46 ++++++++++----------- spec/rubycards/string_spec.rb | 20 ++++----- spec/spec_helper.rb | 1 - 6 files changed, 73 insertions(+), 82 deletions(-) delete mode 100644 spec/factory.rb diff --git a/Gemfile b/Gemfile index bb288d8..567e6e2 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,6 @@ gem 'colored' gem 'rake' group :test do - gem 'rspec' + gem 'rspec', '~> 3.0' gem 'coveralls', require: false end diff --git a/spec/factory.rb b/spec/factory.rb deleted file mode 100644 index 6881763..0000000 --- a/spec/factory.rb +++ /dev/null @@ -1,10 +0,0 @@ -FactoryGirl.define do - factory :card do - end - - factory :deck do - end - - factory :hand do - end -end \ No newline at end of file diff --git a/spec/rubycards/card_spec.rb b/spec/rubycards/card_spec.rb index 1ee7885..090bdc8 100644 --- a/spec/rubycards/card_spec.rb +++ b/spec/rubycards/card_spec.rb @@ -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 - 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,11 +65,11 @@ 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 @@ -76,7 +77,7 @@ 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,8 +133,8 @@ 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 @@ -140,8 +142,8 @@ 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 diff --git a/spec/rubycards/deck_spec.rb b/spec/rubycards/deck_spec.rb index 0c888e5..d8e63c6 100644 --- a/spec/rubycards/deck_spec.rb +++ b/spec/rubycards/deck_spec.rb @@ -7,27 +7,27 @@ describe '#initialize' do it 'initializes 52 cards' do - deck.cards.count.should == 52 + expect(deck.cards.count).to eq 52 # test indexing - deck[0].should be_a Card + expect(deck[0]).to be_a Card # test enumerability - deck.each { |card| card.should be_a Card } + deck.each { |card| expect(card).to be_a Card } end it "initializes four suits" do suits = deck.cards.group_by { |c| c.suit } - suits.count.should == 4 + expect(suits.count).to be 4 end ["Clubs", "Diamonds", "Hearts", "Spades"].each do |suit| it "initializes 13 cards for #{suit}" do cards = deck.cards.select { |c| c.suit == suit } - cards.count.should == 13 + expect(cards.count).to be 13 end it "should include ranks of different ranks" do cards = deck.cards.select { |c| c.suit == suit } - cards.group_by { |x| x.rank }.count.should == 13 + expect(cards.group_by { |x| x.rank }.count).to be 13 end end end @@ -36,17 +36,16 @@ it 'shuffles the cards' do cards_before_shuffling = deck.cards.dup deck.shuffle! - deck.cards.should_not == cards_before_shuffling + expect(deck.cards).not_to eq cards_before_shuffling end it "should should shuffle the internal cards array" do - cards_before_shuffling = deck.cards.dup expect(deck.instance_variable_get("@cards")).to receive(:shuffle!) deck.shuffle! end it 'returns itself' do - should == deck.shuffle! + expect(deck).to eq deck.shuffle! end end @@ -54,8 +53,8 @@ it 'draws a single card from the deck' do first_card = deck.cards.first cards_expected_after_draw = deck.cards[1..-1] - deck.draw.same_as?(first_card).should == true - deck.cards.should == cards_expected_after_draw + expect(deck.draw).to be_same_as first_card + expect(deck.cards).to eq cards_expected_after_draw end end @@ -78,6 +77,7 @@ context 'cutting the first card' do it 'returns itself' do + expect(deck).to eq deck.cut!(0) should == deck.cut!(0) end @@ -86,11 +86,11 @@ deck.cut!(0) - deck.cards[0].suit.should == cards_before_cutting[1].suit - deck.cards[0].rank.should == cards_before_cutting[1].rank + expect(deck.cards[0].suit).to eq cards_before_cutting[1].suit + expect(deck.cards[0].rank).to eq cards_before_cutting[1].rank - deck.cards[-1].suit.should == cards_before_cutting[0].suit - deck.cards[-1].rank.should == cards_before_cutting[0].rank + expect(deck.cards[-1].suit).to eq cards_before_cutting[0].suit + expect(deck.cards[-1].rank).to eq cards_before_cutting[0].rank end it 'should return the same number of cards' do @@ -98,7 +98,7 @@ deck.cut!(0) - deck.cards.count.should == cards_before_cutting.count + expect(deck.cards.count).to eq cards_before_cutting.count end end @@ -108,13 +108,13 @@ deck.cut!(1) - deck.cards[0].suit.should == cards_before_cutting[2].suit - deck.cards[0].rank.should == cards_before_cutting[2].rank + expect(deck.cards[0].suit).to eq cards_before_cutting[2].suit + expect(deck.cards[0].rank).to eq cards_before_cutting[2].rank - deck.cards[-2].suit.should == cards_before_cutting[0].suit - deck.cards[-2].rank.should == cards_before_cutting[0].rank - deck.cards[-1].suit.should == cards_before_cutting[1].suit - deck.cards[-1].rank.should == cards_before_cutting[1].rank + expect(deck.cards[-2].suit).to eq cards_before_cutting[0].suit + expect(deck.cards[-2].rank).to eq cards_before_cutting[0].rank + expect(deck.cards[-1].suit).to eq cards_before_cutting[1].suit + expect(deck.cards[-1].rank).to eq cards_before_cutting[1].rank end it 'should return the same number of cards' do @@ -122,7 +122,7 @@ deck.cut!(1) - deck.cards.count.should == cards_before_cutting.count + expect(deck.cards.count).to eq cards_before_cutting.count end end end diff --git a/spec/rubycards/string_spec.rb b/spec/rubycards/string_spec.rb index 6f9bd0c..153edc5 100644 --- a/spec/rubycards/string_spec.rb +++ b/spec/rubycards/string_spec.rb @@ -7,17 +7,17 @@ context 'one liners' do # cat <- dog == catdog it 'should concatenate strings' do - 'cat'.next('dog').should == 'catdog' + expect('cat'.next('dog')).to eq 'catdog' end # hello <- "" == hello it 'should remain unchanged' do - 'hello'.next('').should == 'hello' + expect('hello'.next('')).to eq 'hello' end # "" <- hello == "" it 'should return an empty string' do - ''.next('hello').should == '' + expect(''.next('hello')).to eq '' end end @@ -25,24 +25,24 @@ # aa bb aabb # aa <- bb == aabb it 'should place blocks adjacently' do - "aa\naa".next("bb\nbb").should == "aabb\naabb" - "aaa\naaa\naaa".next("bbb\nbbb\nbbb").should == "aaabbb\naaabbb\naaabbb" + expect("aa\naa".next("bb\nbb")).to eq "aabb\naabb" + expect("aaa\naaa\naaa".next("bbb\nbbb\nbbb")).to eq "aaabbb\naaabbb\naaabbb" end # aa bb aabb # aa <- == aa it 'should stack the second block in its entirety' do - "aa\naa".next("bb").should == "aabb\naa" - "1\n2\n3".next("4\n5").should == "14\n25\n3" + expect("aa\naa".next("bb")).to eq "aabb\naa" + expect("1\n2\n3".next("4\n5")).to eq "14\n25\n3" end # aa bb aabb # <- bb == it 'should cut off some of the second block' do - "aa".next("bb\nbb").should == "aabb" - "1\n2".next("4\n5\n6").should == "14\n25" + expect("aa".next("bb\nbb")).to eq "aabb" + expect("1\n2".next("4\n5\n6")).to eq "14\n25" end end end -end \ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 40af948..af81d0a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,7 +12,6 @@ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| - config.treat_symbols_as_metadata_keys_with_true_values = true config.run_all_when_everything_filtered = true config.filter_run :focus