spec/lib/trackerific_spec.rb in trackerific-0.1.2 vs spec/lib/trackerific_spec.rb in trackerific-0.2.0
- old
+ new
@@ -1,8 +1,56 @@
require 'spec_helper'
-describe Trackerific::Base do
+class TestBaseClass < Trackerific::Base
+ def required_options
+ [:required, :also_required]
+ end
+end
+
+describe 'Trackerific::Base' do
- it { should respond_to :track_package }
- it { should respond_to :required_options }
+ before(:all) do
+ @base = Trackerific::Base.new
+ end
+
+ describe :required_options do
+ it "should return an Array" do
+ @base.required_options().should be_kind_of Array
+ end
+ end
+
+ describe "tracking_service" do
+ include Trackerific
+ context "when given a UPS tracking number" do
+ specify { tracking_service("1Z12345E0291980793").should eq Trackerific::UPS }
+ end
+ context "when given a USPS tracking number" do
+ specify { tracking_service("EJ958083578US").should eq Trackerific::USPS }
+ end
+ context "when given a FedEx tracking number" do
+ specify { tracking_service("183689015000001").should eq Trackerific::FedEx }
+ end
+ context "when given an invalid tracking number" do
+ specify { tracking_service("invalid tracking number").should be_nil }
+ end
+ end
+
+ context "with a new Trackerific::Base class that has required options" do
+ context "has all the required options" do
+ it "should be able to create a new instance" do
+ t = TestBaseClass.new(:required => true, :also_required => :yup)
+ t.should be_a TestBaseClass
+ end
+ end
+ context "is missing some required options" do
+ it "should raise an ArgumentError" do
+ lambda { TestBaseClass.new() }.should raise_error(ArgumentError)
+ end
+ end
+ context "has an invalid option" do
+ it "should raise an ArgumentError" do
+ lambda { TestBaseClass.new(:unknown => :argument ) }.should raise_error(ArgumentError)
+ end
+ end
+ end
end