[PATCH aeolus-cli 7/9] Simple refactor of base_command_spec.rb
Petr Blaho
pblaho at redhat.com
Thu Dec 22 22:05:53 UTC 2011
---
spec/command/base_command_spec.rb | 30 ++++++++++++------------------
1 files changed, 12 insertions(+), 18 deletions(-)
diff --git a/spec/command/base_command_spec.rb b/spec/command/base_command_spec.rb
index bc8a0c1..26b044b 100644
--- a/spec/command/base_command_spec.rb
+++ b/spec/command/base_command_spec.rb
@@ -17,9 +17,11 @@ require 'spec_helper'
module Aeolus
module CLI
describe BaseCommand do
+ let( :base_command ) { BaseCommand.new }
+
describe "configure_active_resource" do
it "should setup ActiveResource with endpoint and authentication" do
- basec = BaseCommand.new
+ base_command
Aeolus::CLI::Base.site.to_s.should == "https://localhost/conductor/api"
Aeolus::CLI::Base.user.to_s.should == "admin"
Aeolus::CLI::Base.password.to_s.should == "password"
@@ -27,38 +29,32 @@ module Aeolus
end
describe "#read_file" do
-
it "should return nil when it cannot find file" do
- b = BaseCommand.new
- b.send(:read_file, "foo.fake").should be_nil
+ base_command.send(:read_file, "foo.fake").should be_nil
end
it "should read file content into string variable" do
- b = BaseCommand.new
- template_str = b.send(:read_file, "#{File.dirname(__FILE__)}" + "/../../examples/custom_repo.tdl")
+ template_str = base_command.send(:read_file, "#{File.dirname(__FILE__)}" + "/../../examples/custom_repo.tdl")
template_str.should include("<template>")
end
end
describe "#is_file?" do
it "should return false if no file found" do
- b = BaseCommand.new
- b.send(:is_file?, "foo.fake").should be_false
+ base_command.send(:is_file?, "foo.fake").should be_false
end
it "should return true if file found" do
- b = BaseCommand.new
valid_file = "#{File.dirname(__FILE__)}" + "/../../examples/aeolus-cli"
- b.instance_eval {@config_location = valid_file}
- b.send(:is_file?, valid_file).should be_true
+ base_command.instance_eval {@config_location = valid_file}
+ base_command.send(:is_file?, valid_file).should be_true
end
end
describe "#write_file" do
it "should write a new file" do
- b = BaseCommand.new
new_file = "/tmp/foo.fake"
- b.instance_eval {@config_location = new_file}
- b.send(:write_file)
+ base_command.instance_eval {@config_location = new_file}
+ base_command.send(:write_file)
conf = YAML::load(File.open(File.expand_path(new_file)))
conf.has_key?(:conductor).should be_true
File.delete(new_file)
@@ -67,14 +63,12 @@ module Aeolus
describe "#validate_xml_document?" do
it "should return errors given non compliant xml" do
- b = BaseCommand.new
- errors = b.send(:validate_xml_document, "examples/tdl.rng", File.read("spec/fixtures/invalid_template.tdl"))
+ errors = base_command.send(:validate_xml_document, "examples/tdl.rng", File.read("spec/fixtures/invalid_template.tdl"))
errors.length.should > 0
end
it "should return no errors" do
- b = BaseCommand.new
- errors = b.send(:validate_xml_document, "examples/tdl.rng", File.read("spec/fixtures/valid_template.tdl"))
+ errors = base_command.send(:validate_xml_document, "examples/tdl.rng", File.read("spec/fixtures/valid_template.tdl"))
errors.length.should == 0
end
end
--
1.7.7.4
More information about the aeolus-devel
mailing list