diff options
author | danielsdeleo <dan@opscode.com> | 2012-12-17 13:58:31 -0800 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2012-12-18 14:49:17 -0800 |
commit | 8e6c56dbbcddda8635dff0eee09f762f755ddd65 (patch) | |
tree | 56b92a6559a533f8cae1bb2082fba473982e96de | |
parent | 80c952472d022de20ac4bbcb34ee3d6efd0071cf (diff) | |
download | chef-8e6c56dbbcddda8635dff0eee09f762f755ddd65.tar.gz |
[CHEF-3689] refactor ApiClient test suite
remove redundant tests, use declarative and formal language
-rw-r--r-- | spec/unit/api_client_spec.rb | 89 |
1 files changed, 32 insertions, 57 deletions
diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb index 4364bc1f16..1ed2cae67f 100644 --- a/spec/unit/api_client_spec.rb +++ b/spec/unit/api_client_spec.rb @@ -26,78 +26,53 @@ describe Chef::ApiClient do @client = Chef::ApiClient.new end - describe "initialize" do - it "should be a Chef::ApiClient" do - @client.should be_a_kind_of(Chef::ApiClient) - end + it "has a name attribute" do + @client.name("ops_master") + @client.name.should == "ops_master" end - describe "name" do - it "should let you set the name to a string" do - @client.name("ops_master").should == "ops_master" - end - - it "should return the current name" do - @client.name "ops_master" - @client.name.should == "ops_master" - end - - it "should not accept spaces" do - lambda { @client.name "ops master" }.should raise_error(ArgumentError) - end - - it "should throw an ArgumentError if you feed it anything but a string" do - lambda { @client.name Hash.new }.should raise_error(ArgumentError) - end + it "does not allow spaces in the name" do + lambda { @client.name "ops master" }.should raise_error(ArgumentError) end - describe "admin" do - it "should let you set the admin bit" do - @client.admin(true).should == true - end + it "only allows string values for the name" do + lambda { @client.name Hash.new }.should raise_error(ArgumentError) + end - it "should return the current admin value" do - @client.admin true - @client.admin.should == true - end + it "has an admin flag attribute" do + @client.admin(true) + @client.admin.should be_true + end - it "should default to false" do - @client.admin.should == false - end + it "defaults to non-admin" do + @client.admin.should be_false + end - it "should throw an ArgumentError if you feed it anything but true or false" do - lambda { @client.name Hash.new }.should raise_error(ArgumentError) - end + it "allows only boolean values for the admin flag" do + lambda { @client.admin(false) }.should_not raise_error + lambda { @client.admin(Hash.new) }.should raise_error(ArgumentError) end - describe "public_key" do - it "should let you set the public key" do - @client.public_key("super public").should == "super public" - end - it "should return the current public key" do - @client.public_key("super public") - @client.public_key.should == "super public" - end + it "has a public key attribute" do + @client.public_key("super public") + @client.public_key.should == "super public" + end - it "should throw an ArgumentError if you feed it something lame" do - lambda { @client.public_key Hash.new }.should raise_error(ArgumentError) - end + it "accepts only String values for the public key" do + lambda { @client.public_key "" }.should_not raise_error + lambda { @client.public_key Hash.new }.should raise_error(ArgumentError) end - describe "private_key" do - it "should let you set the private key" do - @client.private_key("super private").should == "super private" - end - it "should return the private key" do - @client.private_key("super private") - @client.private_key.should == "super private" - end + it "has a private key attribute" do + @client.private_key("super private") + @client.private_key.should == "super private" + end - it "should throw an ArgumentError if you feed it something lame" do - lambda { @client.private_key Hash.new }.should raise_error(ArgumentError) - end + it "accepts only String values for the private key" do + lambda { @client.private_key "" }.should_not raise_error + lambda { @client.private_key Hash.new }.should raise_error(ArgumentError) end describe "when serializing to JSON" do |