This does not apply as it's own patch, it should go on top of the previous one in the series. I wanted to suggest using mock, but thought altering an existing set of tests would be easier than trying to explain.
I don't care about this being its own patch, so feel free to just git apply it on top of the previous one, then git commit --amend once everything is as desired.
The big thing is, we stub out connect, as DeltaCloud (client) is a collaborator, we should not require a core instance to be running just to make our tests pass. DeltaCloud should be tested with its own codebase (which it is).
One piece which should be tested that I have not added yet is for the connect method, there should be another mock for the logger. what we really want to test is if the logger receives the message that it should. If this turns out to be too problematic, it can be added later, but I think it would be a useful test. --- src/spec/models/provider_spec.rb | 54 +++++++++++++++++++------------------- 1 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/src/spec/models/provider_spec.rb b/src/spec/models/provider_spec.rb index daca748..64aec81 100644 --- a/src/spec/models/provider_spec.rb +++ b/src/spec/models/provider_spec.rb @@ -2,54 +2,43 @@ require 'spec_helper'
describe Provider do before(:each) do + @client = mock('DeltaCloud', :null_object => true) + Provider.stub!(:connect).and_return(@client) + @provider = Factory.create(:mock_provider) + end + + it "should return a client object" do + @provider.send(:valid_framework?).should be_true end
it "should validate mock provider" do - provider = Factory(:mock_provider) - provider.should be_valid + @provider.should be_valid end
it "should require a valid name" do - provider = Factory.create(:mock_provider) [nil, ""].each do |invalid_value| - provider.name = invalid_value - provider.should_not be_valid + @provider.name = invalid_value + @provider.should_not be_valid end end
it "should require a valid cloud_type" do - provider = Factory.create(:mock_provider) [nil, ""].each do |invalid_value| - provider.cloud_type = invalid_value - provider.should_not be_valid + @provider.cloud_type = invalid_value + @provider.should_not be_valid end end
it "should require a valid url" do - provider = Factory.create(:mock_provider) [nil, ""].each do |invalid_value| - provider.url = invalid_value - provider.should_not be_valid + @provider.url = invalid_value + @provider.should_not be_valid end end
- it "should be able to connect to the specified framework" do - provider = Factory.create(:mock_provider) - deltacloud = provider.connect - provider.should be_valid - deltacloud.should_not be_nil - - provider.url = "http://totally.not/there" - deltacloud = provider.connect - provider.should have(1).error_on(:url) - provider.should_not be_valid - deltacloud.should be_nil - end - - it "should require unique name" do - provider1 = Factory.create(:mock_provider) - provider2 = Factory.create(:mock_provider) + provider1 = Factory.create :mock_provider + provider2 = Factory.create :mock_provider provider1.should be_valid provider2.should be_valid
@@ -57,4 +46,15 @@ describe Provider do provider2.should_not be_valid end
+ it "should be able to connect to the specified framework" do + @provider.should be_valid + @provider.connect.should_not be_nil + + @provider.url = "http://totally.not/there" + @provider.stub(:connect).and_return(nil) + deltacloud = @provider.connect + @provider.should have(1).error_on(:url) + @provider.should_not be_valid + deltacloud.should be_nil + end end