Use RSpec's let feature instead of instance variables.
This commit is contained in:
@@ -1,8 +1,13 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe "homesick" do
|
describe "homesick" do
|
||||||
|
let(:home) { create_construct }
|
||||||
|
after { home.destroy! }
|
||||||
|
|
||||||
|
let(:castles) { home.directory(".homesick/repos") }
|
||||||
|
|
||||||
let(:homesick) { Homesick.new }
|
let(:homesick) { Homesick.new }
|
||||||
before { silence! }
|
before { homesick.stub!(:repos_dir).and_return(castles) }
|
||||||
|
|
||||||
describe "clone" do
|
describe "clone" do
|
||||||
context "of a file" do
|
context "of a file" do
|
||||||
@@ -12,13 +17,13 @@ describe "homesick" do
|
|||||||
|
|
||||||
homesick.clone local_repo
|
homesick.clone local_repo
|
||||||
|
|
||||||
@repos_dir.join("wtf").readlink.should == local_repo
|
castles.join("wtf").readlink.should == local_repo
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when it exists in a repo directory" do
|
context "when it exists in a repo directory" do
|
||||||
before do
|
before do
|
||||||
@existing_castle = given_castle("existing_castle")
|
existing_castle = given_castle("existing_castle")
|
||||||
@existing_dir = @existing_castle.parent
|
@existing_dir = existing_castle.parent
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not symlink" do
|
it "should not symlink" do
|
||||||
@@ -88,7 +93,7 @@ describe "homesick" do
|
|||||||
|
|
||||||
homesick.symlink("glencairn")
|
homesick.symlink("glencairn")
|
||||||
|
|
||||||
@user_dir.join(".some_dotfile").readlink.should == dotfile
|
home.join(".some_dotfile").readlink.should == dotfile
|
||||||
end
|
end
|
||||||
|
|
||||||
it "links non-dotfiles from a castle to the home folder" do
|
it "links non-dotfiles from a castle to the home folder" do
|
||||||
@@ -96,7 +101,7 @@ describe "homesick" do
|
|||||||
|
|
||||||
homesick.symlink("glencairn")
|
homesick.symlink("glencairn")
|
||||||
|
|
||||||
@user_dir.join("bin").readlink.should == dotfile
|
home.join("bin").readlink.should == dotfile
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -127,7 +132,7 @@ describe "homesick" do
|
|||||||
it "should move the tracked file into the castle" do
|
it "should move the tracked file into the castle" do
|
||||||
castle = given_castle('castle_repo')
|
castle = given_castle('castle_repo')
|
||||||
|
|
||||||
some_rc_file = @user_dir.file '.some_rc_file'
|
some_rc_file = home.file '.some_rc_file'
|
||||||
|
|
||||||
homesick.track(some_rc_file.to_s, 'castle_repo')
|
homesick.track(some_rc_file.to_s, 'castle_repo')
|
||||||
|
|
||||||
|
|||||||
@@ -8,24 +8,16 @@ require 'construct'
|
|||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.include Construct::Helpers
|
config.include Construct::Helpers
|
||||||
|
|
||||||
config.before do
|
config.before { ENV['HOME'] = home.to_s }
|
||||||
@user_dir = create_construct
|
|
||||||
ENV['HOME'] = @user_dir.to_s
|
|
||||||
|
|
||||||
@repos_dir = @user_dir.directory(".homesick/repos")
|
config.before { silence! }
|
||||||
homesick.stub!(:repos_dir).and_return(@repos_dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
config.after do
|
|
||||||
@user_dir.destroy!
|
|
||||||
end
|
|
||||||
|
|
||||||
def silence!
|
def silence!
|
||||||
homesick.stub(:say_status)
|
homesick.stub(:say_status)
|
||||||
end
|
end
|
||||||
|
|
||||||
def given_castle(name, path=name)
|
def given_castle(name, path=name)
|
||||||
@repos_dir.directory(path) do |castle|
|
castles.directory(path) do |castle|
|
||||||
Dir.chdir(castle) do
|
Dir.chdir(castle) do
|
||||||
system "git init >/dev/null 2>&1"
|
system "git init >/dev/null 2>&1"
|
||||||
system "git remote add origin git://github.com/technicalpickles/#{name}.git >/dev/null 2>&1"
|
system "git remote add origin git://github.com/technicalpickles/#{name}.git >/dev/null 2>&1"
|
||||||
|
|||||||
Reference in New Issue
Block a user