rubyoffrails / episode1-summer2012 Goto Github PK
View Code? Open in Web Editor NEWBlackjack: A Casino game. No gambling, just skill!
License: MIT License
Blackjack: A Casino game. No gambling, just skill!
License: MIT License
if you get 2 aces, wouldn't you get the value of 22 instead of 12?
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.