Skip to content

Instantly share code, notes, and snippets.

@zjfong
Created September 30, 2016 19:19
Show Gist options
  • Save zjfong/c59a82838c4df5885a240b1ef7c3406f to your computer and use it in GitHub Desktop.
Save zjfong/c59a82838c4df5885a240b1ef7c3406f to your computer and use it in GitHub Desktop.
Rspec

#Rspec

passing tests
important to understand what the test is asking
refer to spec
refer to helpers.rb

describe - example group
context - scenario
it - example
expect - the test

model spec

RSpec.describe CardDeck, :type => :model do  
describe "#shuffle" do
  it "returns a shuffled array of cards" do
    expect(@card_deck.shuffle).to be_an Array
    shuffled_cards = @card_deck.shuffle.map(&:face)
    expect(shuffled_cards).to match_array sorted_cards
    expect(shuffled_cards).not_to eq sorted_cards
  end
  it "permanently updates the order of cards in @cards" do
    shuffled_cards = @card_deck.shuffle.map(&:face)
    expect(@card_deck.cards.map(&:face)).to eq shuffled_cards
  end
end  

before

let

subject
Use subject in the group scope to explicitly define the value that is returned by the subject method in the example scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment