spec/acceptance/app_spec.rb in prj-0.0.1 vs spec/acceptance/app_spec.rb in prj-0.0.2
- old
+ new
@@ -1,58 +1,62 @@
require 'spec_helper'
-require 'prj/app'
-require 'stringio'
-require 'tmpdir'
+require 'fakefs/spec_helpers'
require 'fileutils'
+require 'prj'
+require 'stringio'
+require 'yaml'
describe "Prj::App" do
- around(:each) do |example|
- Dir.mktmpdir do |root|
- @root = root
- @subdirectories = [
- "foo/.git/",
- "bar/",
- "baz/qux/crisp/.git/",
- "baz/craps/poops/.git/",
- "any/thing/here/"
- ].map { |d| File.join(@root, d) }
- @subdirectories.each { |d| FileUtils.mkdir_p(d) }
- @sink = StringIO.new
- example.run
- end
+ include FakeFS::SpecHelpers
+
+ let(:output) { StringIO.new }
+ let(:root) { "/Projects" }
+ let(:subdirectories) do
+ [
+ "foo/.git/",
+ "bar/",
+ "baz/qux/crisp/.git/",
+ "baz/craps/poops/.git/",
+ "any/thing/here/"
+ ].map { |d| File.join(root, d) }
end
+ before(:each) do
+ FileUtils.mkdir_p(root)
+ subdirectories.each { |d| FileUtils.mkdir_p(d) }
+ end
+
context "with default projcts root" do
- around(:each) do |example|
- with_projects_root(@root) do
- example.run
+ it "prints matching directory and returns 0" do
+ with_config("projects_root" => root) do
+ Prj::App.new(output, ["ap"]).run.should == 0
+ output.string.chomp.should == File.join(root, "baz/craps/poops")
end
end
- it "prints matching directory and returns 0" do
- Prj::App.new(@sink, ["ap"]).run.should == 0
- @sink.string.chomp.should == File.join(@root, "baz/craps/poops")
- end
-
it "prints projects root and returns 0 if directory not found" do
- Prj::App.new(@sink, ["nothingtofind"]).run.should == 0
- @sink.string.chomp.should == @root + "/"
+ with_config("projects_root" => root) do
+ Prj::App.new(output, ["nothingtofind"]).run.should == 0
+ output.string.chomp.should == root + "/"
+ end
end
+ end
+ it "uses ~/.prj.yml as config file" do
+ Prj::App.config_path.should == File.expand_path("~/.prj.yml")
end
- it "Uses project root from config if available" do
- File.should_receive(:read).with(File.expand_path("~/.prj"))
- Prj::App.new(@sink, ["something"]).run.should == 0
+ it "defaults to ~/Projects as default projects root" do
+ Prj::App.new(output, ["asdf"]).config.fetch("projects_root").should == File.expand_path("~/Projects")
end
- def with_projects_root(root)
- tmp = Prj::App.default_projects_root
- Prj::App.default_projects_root = root
- Prj::App.ignore_config = true
+ def with_config(config = {})
+ tmp = Prj::App.config_path
+ config_path = ".prj.yml"
+ File.open(config_path, "w") { |f| f.write YAML.dump(config) }
+ Prj::App.config_path = config_path
yield
- Prj::App.default_projects_root = tmp
- Prj::App.ignore_config = false
+ ensure
+ Prj::App.config_path = tmp
end
end
-