Permalink
Browse files

Convert specs to the new RSpec expectation syntax

  • Loading branch information...
1 parent 7445a6d commit b75e0ac4e3f0b36fed2d83e2f7d2603869c390a7 @sferik sferik committed Oct 10, 2012
@@ -7,19 +7,19 @@
end
def create_file(destination=nil, config={}, options={})
- @base = MyCounter.new([1,2], options, { :destination_root => destination_root })
+ @base = MyCounter.new([1, 2], options, { :destination_root => destination_root })
@base.stub!(:file_name).and_return('rdoc')
@action = Thor::Actions::CreateFile.new(@base, destination, "CONFIGURATION",
{ :verbose => !@silence }.merge(config))
end
def invoke!
- capture(:stdout){ @action.invoke! }
+ capture(:stdout) { @action.invoke! }
end
def revoke!
- capture(:stdout){ @action.revoke! }
+ capture(:stdout) { @action.revoke! }
end
def silence!
@@ -30,36 +30,36 @@ def silence!
it "creates a file" do
create_file("doc/config.rb")
invoke!
- File.exists?(File.join(destination_root, "doc/config.rb")).should be_true
+ expect(File.exists?(File.join(destination_root, "doc/config.rb"))).to be_true
end
it "does not create a file if pretending" do
create_file("doc/config.rb", {}, :pretend => true)
invoke!
- File.exists?(File.join(destination_root, "doc/config.rb")).should be_false
+ expect(File.exists?(File.join(destination_root, "doc/config.rb"))).to be_false
end
it "shows created status to the user" do
create_file("doc/config.rb")
- invoke!.should == " create doc/config.rb\n"
+ expect(invoke!).to eq(" create doc/config.rb\n")
end
it "does not show any information if log status is false" do
silence!
create_file("doc/config.rb")
- invoke!.should be_empty
+ expect(invoke!).to be_empty
end
it "returns the given destination" do
capture(:stdout) do
- create_file("doc/config.rb").invoke!.should == "doc/config.rb"
+ expect(create_file("doc/config.rb").invoke!).to eq("doc/config.rb")
end
end
it "converts encoded instructions" do
create_file("doc/%file_name%.rb.tt")
invoke!
- File.exists?(File.join(destination_root, "doc/rdoc.rb.tt")).should be_true
+ expect(File.exists?(File.join(destination_root, "doc/rdoc.rb.tt"))).to be_true
end
describe "when file exists" do
@@ -72,7 +72,7 @@ def silence!
it "shows identical status" do
create_file("doc/config.rb")
invoke!
- invoke!.should == " identical doc/config.rb\n"
+ expect(invoke!).to eq(" identical doc/config.rb\n")
end
end
@@ -82,46 +82,46 @@ def silence!
end
it "shows forced status to the user if force is given" do
- create_file("doc/config.rb", {}, :force => true).should_not be_identical
- invoke!.should == " force doc/config.rb\n"
+ expect(create_file("doc/config.rb", {}, :force => true)).not_to be_identical
+ expect(invoke!).to eq(" force doc/config.rb\n")
end
it "shows skipped status to the user if skip is given" do
- create_file("doc/config.rb", {}, :skip => true).should_not be_identical
- invoke!.should == " skip doc/config.rb\n"
+ expect(create_file("doc/config.rb", {}, :skip => true)).not_to be_identical
+ expect(invoke!).to eq(" skip doc/config.rb\n")
end
it "shows forced status to the user if force is configured" do
- create_file("doc/config.rb", :force => true).should_not be_identical
- invoke!.should == " force doc/config.rb\n"
+ expect(create_file("doc/config.rb", :force => true)).not_to be_identical
+ expect(invoke!).to eq(" force doc/config.rb\n")
end
it "shows skipped status to the user if skip is configured" do
- create_file("doc/config.rb", :skip => true).should_not be_identical
- invoke!.should == " skip doc/config.rb\n"
+ expect(create_file("doc/config.rb", :skip => true)).not_to be_identical
+ expect(invoke!).to eq(" skip doc/config.rb\n")
end
it "shows conflict status to ther user" do
- create_file("doc/config.rb").should_not be_identical
+ expect(create_file("doc/config.rb")).not_to be_identical
$stdin.should_receive(:gets).and_return('s')
file = File.join(destination_root, 'doc/config.rb')
content = invoke!
- content.should =~ /conflict doc\/config\.rb/
- content.should =~ /Overwrite #{file}\? \(enter "h" for help\) \[Ynaqdh\]/
- content.should =~ /skip doc\/config\.rb/
+ expect(content).to match(/conflict doc\/config\.rb/)
+ expect(content).to match(/Overwrite #{file}\? \(enter "h" for help\) \[Ynaqdh\]/)
+ expect(content).to match(/skip doc\/config\.rb/)
end
it "creates the file if the file collision menu returns true" do
create_file("doc/config.rb")
$stdin.should_receive(:gets).and_return('y')
- invoke!.should =~ /force doc\/config\.rb/
+ expect(invoke!).to match(/force doc\/config\.rb/)
end
it "skips the file if the file collision menu returns false" do
create_file("doc/config.rb")
$stdin.should_receive(:gets).and_return('n')
- invoke!.should =~ /skip doc\/config\.rb/
+ expect(invoke!).to match(/skip doc\/config\.rb/)
end
it "executes the block given to show file content" do
@@ -140,31 +140,31 @@ def silence!
create_file("doc/config.rb")
invoke!
revoke!
- File.exists?(@action.destination).should be_false
+ expect(File.exists?(@action.destination)).to be_false
end
it "does not raise an error if the file does not exist" do
create_file("doc/config.rb")
revoke!
- File.exists?(@action.destination).should be_false
+ expect(File.exists?(@action.destination)).to be_false
end
end
describe "#exists?" do
it "returns true if the destination file exists" do
create_file("doc/config.rb")
- @action.exists?.should be_false
+ expect(@action.exists?).to be_false
invoke!
- @action.exists?.should be_true
+ expect(@action.exists?).to be_true
end
end
describe "#identical?" do
it "returns true if the destination file and is identical" do
create_file("doc/config.rb")
- @action.identical?.should be_false
+ expect(@action.identical?).to be_false
invoke!
- @action.identical?.should be_true
+ expect(@action.identical?).to be_true
end
end
end
@@ -20,7 +20,7 @@ def create_link(destination=nil, config={}, options={})
end
def invoke!
- capture(:stdout){ @action.invoke! }
+ capture(:stdout) { @action.invoke! }
end
def silence!
@@ -32,50 +32,50 @@ def silence!
create_link("doc/config.rb", :symbolic => true)
invoke!
destination_path = File.join(destination_root, "doc/config.rb")
- File.exists?(destination_path).should be_true
- File.symlink?(destination_path).should be_true
+ expect(File.exists?(destination_path)).to be_true
+ expect(File.symlink?(destination_path)).to be_true
end
it "creates a hard link for :symbolic => false" do
create_link(@hardlink_to, :symbolic => false)
invoke!
destination_path = @hardlink_to
- File.exists?(destination_path).should be_true
- File.symlink?(destination_path).should be_false
+ expect(File.exists?(destination_path)).to be_true
+ expect(File.symlink?(destination_path)).to be_false
end
it "creates a symbolic link by default" do
create_link("doc/config.rb")
invoke!
destination_path = File.join(destination_root, "doc/config.rb")
- File.exists?(destination_path).should be_true
- File.symlink?(destination_path).should be_true
+ expect(File.exists?(destination_path)).to be_true
+ expect(File.symlink?(destination_path)).to be_true
end
it "does not create a link if pretending" do
create_link("doc/config.rb", {}, :pretend => true)
invoke!
- File.exists?(File.join(destination_root, "doc/config.rb")).should be_false
+ expect(File.exists?(File.join(destination_root, "doc/config.rb"))).to be_false
end
it "shows created status to the user" do
create_link("doc/config.rb")
- invoke!.should == " create doc/config.rb\n"
+ expect(invoke!).to eq(" create doc/config.rb\n")
end
it "does not show any information if log status is false" do
silence!
create_link("doc/config.rb")
- invoke!.should be_empty
+ expect(invoke!).to be_empty
end
end
describe "#identical?" do
it "returns true if the destination link exists and is identical" do
create_link("doc/config.rb")
- @action.identical?.should be_false
+ expect(@action.identical?).to be_false
invoke!
- @action.identical?.should be_true
+ expect(@action.identical?).to be_true
end
end
end
@@ -28,21 +28,21 @@ def exists_and_identical?(source_path, destination_path)
source = File.join(source_root, source_path, file)
destination = File.join(destination_root, destination_path, file)
- File.exists?(destination).should be_true
- FileUtils.identical?(source, destination).should be_true
+ expect(File.exists?(destination)).to be_true
+ expect(FileUtils.identical?(source, destination)).to be_true
end
end
describe "#invoke!" do
it "raises an error if the source does not exist" do
- lambda {
+ expect {
invoke! "unknown"
- }.should raise_error(Thor::Error, /Could not find "unknown" in any of your source paths/)
+ }.to raise_error(Thor::Error, /Could not find "unknown" in any of your source paths/)
end
- it "should not create a directory in pretend mode" do
+ it "does not create a directory in pretend mode" do
invoke! "doc", "ghost", :pretend => true
- File.exists?("ghost").should be_false
+ expect(File.exists?("ghost")).to be_false
end
it "copies the whole directory recursively to the default destination" do
@@ -59,13 +59,13 @@ def exists_and_identical?(source_path, destination_path)
invoke! ".", "tasks", :recursive => false
file = File.join(destination_root, "tasks", "group.thor")
- File.exists?(file).should be_true
+ expect(File.exists?(file)).to be_true
file = File.join(destination_root, "tasks", "doc")
- File.exists?(file).should be_false
+ expect(File.exists?(file)).to be_false
file = File.join(destination_root, "tasks", "doc", "README")
- File.exists?(file).should be_false
+ expect(File.exists?(file)).to be_false
end
it "copies files from the source relative to the current path" do
@@ -78,60 +78,60 @@ def exists_and_identical?(source_path, destination_path)
it "copies and evaluates templates" do
invoke! "doc", "docs"
file = File.join(destination_root, "docs", "rdoc.rb")
- File.exists?(file).should be_true
- File.read(file).should == "FOO = FOO\n"
+ expect(File.exists?(file)).to be_true
+ expect(File.read(file)).to eq("FOO = FOO\n")
end
it "copies directories and preserved file mode" do
invoke! "preserve", "preserved", :mode => :preserve
original = File.join(source_root, "preserve", "script.sh")
copy = File.join(destination_root, "preserved", "script.sh")
- File.stat(original).mode.should == File.stat(copy).mode
+ expect(File.stat(original).mode).to eq(File.stat(copy).mode)
end
it "copies directories" do
invoke! "doc", "docs"
file = File.join(destination_root, "docs", "components")
- File.exists?(file).should be_true
- File.directory?(file).should be_true
+ expect(File.exists?(file)).to be_true
+ expect(File.directory?(file)).to be_true
end
it "does not copy .empty_directory files" do
invoke! "doc", "docs"
file = File.join(destination_root, "docs", "components", ".empty_directory")
- File.exists?(file).should be_false
+ expect(File.exists?(file)).to be_false
end
it "copies directories even if they are empty" do
invoke! "doc/components", "docs/components"
file = File.join(destination_root, "docs", "components")
- File.exists?(file).should be_true
+ expect(File.exists?(file)).to be_true
end
it "does not copy empty directories twice" do
content = invoke!("doc/components", "docs/components")
- content.should_not =~ /exist/
+ expect(content).not_to match(/exist/)
end
it "logs status" do
content = invoke!("doc")
- content.should =~ /create doc\/README/
- content.should =~ /create doc\/config\.rb/
- content.should =~ /create doc\/rdoc\.rb/
- content.should =~ /create doc\/components/
+ expect(content).to match(/create doc\/README/)
+ expect(content).to match(/create doc\/config\.rb/)
+ expect(content).to match(/create doc\/rdoc\.rb/)
+ expect(content).to match(/create doc\/components/)
end
it "yields a block" do
checked = false
invoke!("doc") do |content|
checked ||= !!(content =~ /FOO/)
end
- checked.should be_true
+ expect(checked).to be_true
end
it "works with glob characters in the path" do
content = invoke!("app{1}")
- content.should =~ /create app\{1\}\/README/
+ expect(content).to match(/create app\{1\}\/README/)
end
end
@@ -140,17 +140,17 @@ def exists_and_identical?(source_path, destination_path)
invoke! "doc"
revoke! "doc"
- File.exists?(File.join(destination_root, "doc", "README")).should be_false
- File.exists?(File.join(destination_root, "doc", "config.rb")).should be_false
- File.exists?(File.join(destination_root, "doc", "components")).should be_false
+ expect(File.exists?(File.join(destination_root, "doc", "README"))).to be_false
+ expect(File.exists?(File.join(destination_root, "doc", "config.rb"))).to be_false
+ expect(File.exists?(File.join(destination_root, "doc", "components"))).to be_false
end
it "works with glob characters in the path" do
invoke! "app{1}"
- File.exists?(File.join(destination_root, "app{1}", "README")).should be_true
+ expect(File.exists?(File.join(destination_root, "app{1}", "README"))).to be_true
revoke! "app{1}"
- File.exists?(File.join(destination_root, "app{1}", "README")).should be_false
+ expect(File.exists?(File.join(destination_root, "app{1}", "README"))).to be_false
end
end
end
Oops, something went wrong.

0 comments on commit b75e0ac

Please sign in to comment.