Skip to content
Browse files

Adds a ticker to the QuotedItem.

  • Loading branch information...
1 parent 0cbc76d commit d57f7a69d7a83522c4113472f04e5ee7e54e9bd5 @conceptric committed May 30, 2012
Showing with 51 additions and 11 deletions.
  1. +51 −11 spec/unit/quoted_item_spec.rb
View
62 spec/unit/quoted_item_spec.rb
@@ -1,18 +1,58 @@
-class QuotedItem
- def initialize
-
+class QuotedItem
+ attr_reader :ticker
+
+ def initialize(ticker)
+ validate_ticker(ticker)
+ @ticker = ticker
end
-
+
+ private
+
+ def validate_ticker(ticker)
+ unless ticker.class == String
+ raise ArgumentError, "Ticker must be a valid string", caller
+ end
+ raise ArgumentError, "Ticker cannot be blank", caller if ticker == ""
+ end
end
describe QuotedItem do
- it "exists" do
- subject.should be_true
- end
-
- describe ".new" do
- it "creates an instance" do
- QuotedItem.new.should be_instance_of QuotedItem
+ context "when created with valid attributes" do
+ subject do
+ QuotedItem.new("TEST.L")
+ end
+
+ it "creates an instance" do
+ subject.should be_instance_of QuotedItem
+ end
+
+ it "has a ticker" do
+ subject.ticker.should == "TEST.L"
+ end
+ end
+
+ context "when created with invalid attributes" do
+ it "raises an ArgumentError when there are no attributes" do
+ expect {QuotedItem.new()}.to raise_error ArgumentError
end
+
+ describe "raises an ArgumentError with invalid ticker types" do
+ def invalid_ticker_helper(ticker_type, message)
+ expect {QuotedItem.new(ticker_type)}.to raise_error ArgumentError,
+ message
+ end
+
+ it "like nil" do
+ invalid_ticker_helper(nil, "Ticker must be a valid string")
+ end
+
+ it "like an integer" do
+ invalid_ticker_helper(10, "Ticker must be a valid string")
+ end
+
+ it "like a blank string" do
+ invalid_ticker_helper("", "Ticker cannot be blank")
+ end
+ end
end
end

0 comments on commit d57f7a6

Please sign in to comment.
Something went wrong with that request. Please try again.