Coder Social home page Coder Social logo

episode1-summer2012's Issues

2 aces?

if you get 2 aces, wouldn't you get the value of 22 instead of 12?

RSpec Expectation syntax

While trying to complete the exercise I ran into a deprecation warning:

Using `should` from rspec-expectations' old `:should` syntax without explicitly 
enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly 
enable `:should` with`config.expect_with(:rspec) { |c| c.syntax = :should }` instead.

This is not a big deal but I then tried went down the road of trying to write the test using the expect syntax, and I'm having trouble with accessing instance variables.
For example:

# Card Class
0 class Card
1
2     attr_reader :suit, :value
3     def initialize(suit, value)
4         @suit = suit
5         @value = value
6     end
7
8 end
# Test case
0 describe Card do
1
2     it "expect to accept suit and value when building" do
3         card = Card.new(:clubs, 10)
4         expect(card).to eq(:clubs)  #<-- I'm unable to use card.suit or card.new.suit(:site, :value)   
5         #expect(card).to eq(10)
6     end
7 end

How would I write this test using the expect syntax?

error message from Rspec:

F

Failures:

  1) Card expect to accept suit and value when building
     Failure/Error: expect(card.value).to eq(10)
     NoMethodError:
       undefined method `value' for #<Card:0x007fa902915c00 @suit=:clubs, @value=10>
     # ./blackjack.rb:18:in `block (2 levels) in <top (required)>'

Finished in 0.00137 seconds (files took 0.16479 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./blackjack.rb:15 # Card expect to accept suit and value when building
Failures:

  1) Card expect to accept suit and value when building
     Failure/Error: expect(card).to eq(:clubs)

       expected: :clubs
            got: #<Card:0x007fc89a8363e0 @suit=:clubs, @value=10>

       (compared using ==)

       Diff:
       @@ -1,2 +1,2 @@
       -:clubs
       +#<Card:0x007fc89a8363e0 @suit=:clubs, @value=10>
     # ./blackjack.rb:17:in `block (2 levels) in <top (required)>'

Finished in 0.02727 seconds (files took 0.15817 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./blackjack.rb:15 # Card expect to accept suit and value when building

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.