I’m trying to raise 2 exceptions when one of my variables is bigger than 13 or less than 1
also I want to raise exception if the type of my card is not one of the defined one.
this is my code :
require "../lib/suit"
class Card
attr_reader :suit,:number
def initialize(suit,number)
raise "CardNumberNotValid" if 1>number>13
raise "SuitNotValid" if suit!=Suit::CLUB or suit!=Suit::HEART or suit!=Suit::DIAMOND or suit!=Suit::SPADE
@suit=suit
@number=number
end
end
and this is my test:
require "rspec"
require "../lib/suit"
require "../lib/card"
describe Card do
it "should check if card number is between 1 and 13" do
expect{Card.new(Suit::CLUB,14)}.to raise_error("CardNumberNotValid")
end
end
The result is below :
Failures:
1) Card should check if card number is between 1 and 13
Failure/Error: expect{Card.new(Suit::CLUB,14)}.to raise_error(“CardNumberNotValid”)
expected Exception with “CardNumberNotValid”, got #’ for false:FalseClass>
# ./card_spec.rb:8Finished in 0.00064 seconds 1 example, 1 failure
Failed examples:
rspec ./card_spec.rb:7 # Card should check if card number is between 1
and 13
can you please help ?
Does not work in Ruby. Use something like: