diff options
| author | Peter Mangiafico | 2011-04-13 13:03:22 -0700 |
|---|---|---|
| committer | Chris Sepic | 2011-06-28 17:24:00 -0500 |
| commit | e93a209bee4419f0d3e8261cd7026774a31db3e4 (patch) | |
| tree | c1a9143da6c9f1b5b93a769eece1e5ec51904f9e /spec | |
| parent | 9e97c290509c1681fbaa9a103332370e331ad9c3 (diff) | |
| download | evernote-e93a209bee4419f0d3e8261cd7026774a31db3e4.tar.bz2 | |
fixed spec tests; updated readme; allow for users to pass in keys in hash
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/evernote/user_store_spec.rb | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/spec/evernote/user_store_spec.rb b/spec/evernote/user_store_spec.rb index dcc33cd..1f769ee 100644 --- a/spec/evernote/user_store_spec.rb +++ b/spec/evernote/user_store_spec.rb @@ -2,44 +2,54 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "Evernote::UserStore" do before(:each) do - @auth_file = File.dirname(__FILE__) + "/auth.yaml" - @env = :sandbox + @user_store_url = "https://sandbox.evernote.com/edam/user" + @config = { + :username => 'cgs', + :password => 'password', + :consumer_key => '12345', + :consumer_secret => 'ABCDE' + } end it "initializes an Evernote::Client and validate the client code version" do client = mock("Evernote::Client", :checkVersion => true) Evernote::Client.should_receive(:new).with(Evernote::EDAM::UserStore::UserStore::Client, "https://sandbox.evernote.com/edam/user", {}).and_return(client) - Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, @env) + Evernote::UserStore.new(@user_store_url, @config) end it "should raise an error on init if the version is not up to date" do Evernote::Client.stub!(:new => mock("Evernote::Client", :checkVersion => false)) lambda { - Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, @env) + Evernote::UserStore.new(@user_store_url, @config) }.should raise_error(Evernote::VersionOutOfDate, "The vendored Evernote client code is out of date and needs to be regenerated") end %w(consumer_key consumer_secret username password).each do |credential| it "raises an exception if no #{credential} is set" do lambda { - Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, :invalid) + Evernote::UserStore.new(@user_store_url, Hash.new) }.should raise_error(ArgumentError, "'consumer_key', 'consumer_secret', 'username' and 'password' are required") end end it "should authenticate" do Evernote::Client.stub!(:new => mock("Evernote::Client", :checkVersion => true)) - user_store = Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, @env) + Evernote::UserStore.new(@user_store_url, @config) user_store.instance_variable_get(:@client).should_receive(:authenticate).with("cgs", "password", "12345", "ABCDE").and_return(nil) user_store.authenticate end + it "should raise an exception if the config parameter is not a hash" do + not_a_hash="hello, I am a string" + Evernote::UserStore.new(@user_store_url, not_a_hash).should raise_error(ArgumentError, "credentials must be passed in as a hash") + end + it "should wrap authentication failure" do Evernote::Client.stub!(:new => mock("Evernote::Client", :checkVersion => true)) - user_store = Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, @env) + Evernote::UserStore.new(@user_store_url, @config) user_store.instance_variable_get(:@client).should_receive(:authenticate).and_raise(Evernote::EDAM::Error::EDAMUserException) lambda { @@ -49,7 +59,7 @@ describe "Evernote::UserStore" do it "should proxy methods" do Evernote::Client.stub!(:new => mock("Evernote::Client", :checkVersion => true)) - user_store = Evernote::UserStore.new("https://sandbox.evernote.com/edam/user", @auth_file, @env) + Evernote::UserStore.new(@user_store_url, @config) user_store.instance_variable_get(:@client).should_receive(:foobar).and_return(nil) user_store.foobar |
