Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0cbc76d
commit d57f7a6
Showing
1 changed file
with
51 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |