spec/lib/onename_spec.rb in openname-0.3 vs spec/lib/onename_spec.rb in openname-0.4

- old
+ new

@@ -1,32 +1,68 @@ require 'spec_helper' +require 'bitcoin' describe Openname, :vcr => { :cassette_name => "openname" } do - it "should have a default endpoint" do - Openname.endpoint.should == "https://www.onename.io" - end - - it "should allow setting a different endpoint and returning to default" do - Openname.endpoint = "https://www.example.com" - Openname.endpoint.should == "https://www.example.com" - Openname.endpoint = nil - Openname.endpoint.should == "https://www.onename.io" - end - - it "should retrieve openname user" do - user = Openname.get("larry") - user.is_a?(Openname::User).should == true - end + it "should have a default endpoint" do + Openname.endpoint.should == "https://www.onename.io" + end + + it "should allow setting a different endpoint and returning to default" do + Openname.endpoint = "https://www.example.com" + Openname.endpoint.should == "https://www.example.com" + Openname.endpoint = nil + Openname.endpoint.should == "https://www.onename.io" + end + + it "should retrieve openname user" do + user = Openname.get("larry") + user.is_a?(Openname::User).should == true + end + + it "should give error if openname user does not exist" do + expect { + user = Openname.get("nothere") + }.to raise_error(NameError) + end context "we've retrieved an openname user" do before :each do @user = Openname.get("larry") end it "should have a openname" do @user.openname.should == "larry" end + it "should have a bitcoin address" do + address = @user.bitcoin_address + Bitcoin.valid_address?(address).should == true + end + end + + context "retrieving Bitcoin addreses" do + it "should retrieve a Bitcoin address" do + address = Openname.get_bitcoin_address("larry") + Bitcoin.valid_address?(address).should == true + + address = Openname.get_bitcoin_address("143xFrxppUD9oQE7mGvQFe23h814YorMBs") + Bitcoin.valid_address?(address).should == true + end + + it "should raise an error when retrieving poorly formed Bitcoin address" do + expect { + address = Openname.get_bitcoin_address("143xFrxpp") + }.to raise_error(ArgumentError) + + end + + it "should raise an error when user has no Bitcoin address" do + expect { + address = Openname.get_bitcoin_address("bitcoinhater") + }.to raise_error(NameError) + + end + end end