spec/shelly/structure_validator_spec.rb in shelly-0.1.13 vs spec/shelly/structure_validator_spec.rb in shelly-0.1.14
- old
+ new
@@ -1,72 +1,78 @@
require "spec_helper"
describe Shelly::StructureValidator do
before do
- File.open("Gemfile", 'w')
- File.open("config.ru", 'w')
@validator = Shelly::StructureValidator.new
+ Grit::Repo.stub_chain(:new, :status).and_return([
+ mock(:path => "Gemfile"), mock(:path => "Gemfile.lock")
+ ])
end
- it "should return Gemfile path" do
- @validator.gemfile_path.should == "Gemfile"
- end
+ describe "#gemfile?" do
+ context "when Gemfile exists" do
+ it "should return true" do
+ @validator.gemfile?.should == true
+ end
+ end
- it "should return Gemfile.lock path" do
- @validator.gemfile_lock_path.should == "Gemfile.lock"
+ context "when Gemfile doesn't exist" do
+ it "should return false" do
+ Grit::Repo.stub_chain(:new, :status) \
+ .and_return([mock(:path => "Gemfile.lock")])
+ @validator.gemfile?.should == false
+ end
+ end
end
- describe "#gemfile_exists?" do
- context "when Gemfile exists" do
+ describe "#gemfile_lock?" do
+ context "when Gemfile.lock exists" do
it "should return true" do
- @validator.gemfile_exists?.should == true
+ @validator.gemfile_lock?.should == true
end
end
- context "when Gemfile doesn't exist" do
+ context "when Gemfile.lock doesn't exist" do
it "should return false" do
- File.delete("Gemfile")
- @validator.gemfile_exists?.should == false
+ Grit::Repo.stub_chain(:new, :status) \
+ .and_return([mock(:path => "Gemfile")])
+ @validator.gemfile_lock?.should == false
end
end
end
- describe "#config_ru_exists?" do
+ describe "#config_ru?" do
before do
- @config_ru = mock(:path => "config.ru")
- Grit::Repo.stub_chain(:new, :status).and_return([@config_ru])
+ Grit::Repo.stub_chain(:new, :status) \
+ .and_return([mock(:path => "config.ru")])
end
context "when config.ru exists" do
it "should return true" do
- @validator.config_ru_exists?.should == true
+ @validator.config_ru?.should == true
end
end
context "when config.ru doesn't exist" do
it "should return false" do
Grit::Repo.stub_chain(:new, :status).and_return([])
- @validator.config_ru_exists?.should == false
+ @validator.config_ru?.should == false
end
end
end
- describe "#gems" do
+ describe "#gem?" do
before do
- @thin = mock(:name => "thin")
- @mysql = mock(:name => "mysql")
+ @validator.stub(:gemfile? => true, :gemfile_lock? => true)
+ Bundler::Definition.stub_chain(:build, :specs).and_return(
+ [mock(:name => "thin"), mock(:name => "mysql")])
end
- it "should return list of used gems" do
- Bundler::Definition.stub_chain(:build, :specs).and_return([@thin, @mysql])
- Bundler::Definition.should_receive(:build).with("Gemfile", "Gemfile.lock", nil)
- @validator.gems.should == ["thin", "mysql"]
+ it "should return true if gem is present" do
+ @validator.gem?("thin").should be_true
end
- context "when gemfile doesn't exist" do
- it "should return empty array" do
- File.delete("Gemfile")
- @validator.gems.should == []
- end
+ it "should return false if gem is missing" do
+ @validator.gem?("rake").should be_false
end
end
end