Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Convert specs to the new RSpec expectation syntax

  • Loading branch information...
commit b75e0ac4e3f0b36fed2d83e2f7d2603869c390a7 1 parent 7445a6d
Erik Michaels-Ober sferik authored
Showing with 824 additions and 820 deletions.
  1. +30 −30 spec/actions/create_file_spec.rb
  2. +12 −12 spec/actions/create_link_spec.rb
  3. +28 −28 spec/actions/directory_spec.rb
  4. +16 −16 spec/actions/empty_directory_spec.rb
  5. +50 −50 spec/actions/file_manipulation_spec.rb
  6. +18 −18 spec/actions/inject_into_file_spec.rb
  7. +56 −56 spec/actions_spec.rb
  8. +69 −69 spec/base_spec.rb
  9. +14 −14 spec/core_ext/hash_with_indifferent_access_spec.rb
  10. +29 −29 spec/core_ext/ordered_hash_spec.rb
  11. +3 −3 spec/exit_condition_spec.rb
  12. +55 −55 spec/group_spec.rb
  13. +26 −26 spec/invocation_spec.rb
  14. +12 −12 spec/parser/argument_spec.rb
  15. +12 −12 spec/parser/arguments_spec.rb
  16. +47 −47 spec/parser/option_spec.rb
  17. +80 −80 spec/parser/options_spec.rb
  18. +11 −11 spec/rake_compat_spec.rb
  19. +8 −8 spec/register_spec.rb
  20. +38 −38 spec/runner_spec.rb
  21. +38 −38 spec/shell/basic_spec.rb
  22. +13 −13 spec/shell/color_spec.rb
  23. +3 −3 spec/shell/html_spec.rb
  24. +7 −7 spec/shell_spec.rb
  25. +4 −0 spec/spec_helper.rb
  26. +11 −11 spec/task_spec.rb
  27. +92 −92 spec/thor_spec.rb
  28. +42 −42 spec/util_spec.rb
60 spec/actions/create_file_spec.rb
View
@@ -7,7 +7,7 @@
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",
@@ -15,11 +15,11 @@ def create_file(destination=nil, config={}, options={})
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
24 spec/actions/create_link_spec.rb
View
@@ -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
56 spec/actions/directory_spec.rb
View
@@ -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,47 +78,47 @@ 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
@@ -126,12 +126,12 @@ def exists_and_identical?(source_path, destination_path)
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
32 spec/actions/empty_directory_spec.rb
View
@@ -11,11 +11,11 @@ def empty_directory(destination, options={})
end
def invoke!
- capture(:stdout){ @action.invoke! }
+ capture(:stdout) { @action.invoke! }
end
def revoke!
- capture(:stdout){ @action.revoke! }
+ capture(:stdout) { @action.revoke! }
end
def base
@@ -24,12 +24,12 @@ def base
describe "#destination" do
it "returns the full destination with the destination_root" do
- empty_directory('doc').destination.should == File.join(destination_root, 'doc')
+ expect(empty_directory('doc').destination).to eq(File.join(destination_root, 'doc'))
end
it "takes relative root into account" do
base.inside('doc') do
- empty_directory('contents').destination.should == File.join(destination_root, 'doc', 'contents')
+ expect(empty_directory('contents').destination).to eq(File.join(destination_root, 'doc', 'contents'))
end
end
end
@@ -37,7 +37,7 @@ def base
describe "#relative_destination" do
it "returns the relative destination to the original destination root" do
base.inside('doc') do
- empty_directory('contents').relative_destination.should == 'doc/contents'
+ expect(empty_directory('contents').relative_destination).to eq('doc/contents')
end
end
end
@@ -45,7 +45,7 @@ def base
describe "#given_destination" do
it "returns the destination supplied by the user" do
base.inside('doc') do
- empty_directory('contents').given_destination.should == 'contents'
+ expect(empty_directory('contents').given_destination).to eq('contents')
end
end
end
@@ -54,26 +54,26 @@ def base
it "copies the file to the specified destination" do
empty_directory("doc")
invoke!
- File.exists?(File.join(destination_root, "doc")).should be_true
+ expect(File.exists?(File.join(destination_root, "doc"))).to be_true
end
it "shows created status to the user" do
empty_directory("doc")
- invoke!.should == " create doc\n"
+ expect(invoke!).to eq(" create doc\n")
end
it "does not create a directory if pretending" do
base.inside("foo", :pretend => true) do
empty_directory("ghost")
end
- File.exists?(File.join(base.destination_root, "ghost")).should be_false
+ expect(File.exists?(File.join(base.destination_root, "ghost"))).to be_false
end
describe "when directory exists" do
it "shows exist status" do
empty_directory("doc")
invoke!
- invoke!.should == " exist doc\n"
+ expect(invoke!).to eq(" exist doc\n")
end
end
end
@@ -83,16 +83,16 @@ def base
empty_directory("doc")
invoke!
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
empty_directory("doc")
- @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
@@ -104,15 +104,15 @@ def base
end
it "accepts and executes a 'legal' %\w+% encoded instruction" do
- @action.send(:convert_encoded_instructions, "%file_name%.txt").should == "expected.txt"
+ expect(@action.send(:convert_encoded_instructions, "%file_name%.txt")).to eq("expected.txt")
end
it "ignores an 'illegal' %\w+% encoded instruction" do
- @action.send(:convert_encoded_instructions, "%some_name%.txt").should == "%some_name%.txt"
+ expect(@action.send(:convert_encoded_instructions, "%some_name%.txt")).to eq("%some_name%.txt")
end
it "ignores incorrectly encoded instruction" do
- @action.send(:convert_encoded_instructions, "%some.name%.txt").should == "%some.name%.txt"
+ expect(@action.send(:convert_encoded_instructions, "%some.name%.txt")).to eq("%some.name%.txt")
end
it "raises an error if the instruction refers to a private method" do
100 spec/actions/file_manipulation_spec.rb
View
@@ -8,15 +8,15 @@ def runner(options={})
end
def action(*args, &block)
- capture(:stdout){ runner.send(*args, &block) }
+ capture(:stdout) { runner.send(*args, &block) }
end
def exists_and_identical?(source, destination)
destination = File.join(destination_root, destination)
- File.exists?(destination).should be_true
+ expect(File.exists?(destination)).to be_true
source = File.join(source_root, source)
- FileUtils.should be_identical(source, destination)
+ expect(FileUtils).to be_identical(source, destination)
end
def file
@@ -41,12 +41,12 @@ def file
it "logs status" do
FileUtils.should_receive(:chmod_R).with(0755, file)
- action(:chmod, "foo", 0755).should == " chmod foo\n"
+ expect(action(:chmod, "foo", 0755)).to eq(" chmod foo\n")
end
it "does not log status if required" do
FileUtils.should_receive(:chmod_R).with(0755, file)
- action(:chmod, "foo", 0755, :verbose => false).should be_empty
+ expect(action(:chmod, "foo", 0755, :verbose => false)).to be_empty
end
end
@@ -72,18 +72,18 @@ def file
action :copy_file, "preserve/script.sh", :mode => :preserve
original = File.join(source_root, "preserve/script.sh")
copy = File.join(destination_root, "preserve/script.sh")
- File.stat(original).mode.should == File.stat(copy).mode
+ expect(File.stat(original).mode).to eq(File.stat(copy).mode)
end
it "logs status" do
- action(:copy_file, "task.thor").should == " create task.thor\n"
+ expect(action(:copy_file, "task.thor")).to eq(" create task.thor\n")
end
it "accepts a block to change output" do
action :copy_file, "task.thor" do |content|
"OMG" + content
end
- File.read(File.join(destination_root, "task.thor")).should =~ /^OMG/
+ expect(File.read(File.join(destination_root, "task.thor"))).to match(/^OMG/)
end
end
@@ -106,7 +106,7 @@ def file
end
it "logs status" do
- action(:link_file, "task.thor").should == " create task.thor\n"
+ expect(action(:link_file, "task.thor")).to eq(" create task.thor\n")
end
end
@@ -128,19 +128,19 @@ def file
it "yields file content to a block" do
action :get, "doc/README" do |content|
- content.should == "__start__\nREADME\n__end__\n"
+ expect(content).to eq("__start__\nREADME\n__end__\n")
end
end
it "logs status" do
- action(:get, "doc/README", "docs/README").should == " create docs/README\n"
+ expect(action(:get, "doc/README", "docs/README")).to eq(" create docs/README\n")
end
it "accepts http remote sources" do
body = "__start__\nHTTPFILE\n__end__\n"
FakeWeb.register_uri(:get, 'http://example.com/file.txt', :body => body)
- action :get, 'http://example.com/file.txt' do |content|
- content.should == body
+ action :get, "http://example.com/file.txt" do |content|
+ expect(content).to eq(body)
end
FakeWeb.clean_registry
end
@@ -148,8 +148,8 @@ def file
it "accepts https remote sources" do
body = "__start__\nHTTPSFILE\n__end__\n"
FakeWeb.register_uri(:get, 'https://example.com/file.txt', :body => body)
- action :get, 'https://example.com/file.txt' do |content|
- content.should == body
+ action :get, "https://example.com/file.txt" do |content|
+ expect(content).to eq(body)
end
FakeWeb.clean_registry
end
@@ -160,7 +160,7 @@ def file
action :template, "doc/block_helper.rb"
file = File.join(destination_root, "doc/block_helper.rb")
- File.read(file).should == "Hello world!"
+ expect(File.read(file)).to eq("Hello world!")
end
it "evaluates the template given as source" do
@@ -168,38 +168,38 @@ def file
action :template, "doc/config.rb"
file = File.join(destination_root, "doc/config.rb")
- File.read(file).should == "class Config; end\n"
+ expect(File.read(file)).to eq("class Config; end\n")
end
it "copies the template to the specified destination" do
action :template, "doc/config.rb", "doc/configuration.rb"
file = File.join(destination_root, "doc/configuration.rb")
- File.exists?(file).should be_true
+ expect(File.exists?(file)).to be_true
end
it "converts enconded instructions" do
runner.should_receive(:file_name).and_return("rdoc")
action :template, "doc/%file_name%.rb.tt"
file = File.join(destination_root, "doc/rdoc.rb")
- File.exists?(file).should be_true
+ expect(File.exists?(file)).to be_true
end
it "logs status" do
- capture(:stdout){ runner.template("doc/config.rb") }.should == " create doc/config.rb\n"
+ expect(capture(:stdout) { runner.template("doc/config.rb") }).to eq(" create doc/config.rb\n")
end
it "accepts a block to change output" do
action :template, "doc/config.rb" do |content|
"OMG" + content
end
- File.read(File.join(destination_root, "doc/config.rb")).should =~ /^OMG/
+ expect(File.read(File.join(destination_root, "doc/config.rb"))).to match(/^OMG/)
end
it "guesses the destination name when given only a source" do
action :template, "doc/config.yaml.tt"
file = File.join(destination_root, "doc/config.yaml")
- File.exists?(file).should be_true
+ expect(File.exists?(file)).to be_true
end
end
@@ -215,84 +215,84 @@ def file
describe "#remove_file" do
it "removes the file given" do
action :remove_file, "doc/README"
- File.exists?(file).should be_false
+ expect(File.exists?(file)).to be_false
end
it "removes directories too" do
action :remove_dir, "doc"
- File.exists?(File.join(destination_root, "doc")).should be_false
+ expect(File.exists?(File.join(destination_root, "doc"))).to be_false
end
it "does not remove if pretending" do
runner(:pretend => true)
action :remove_file, "doc/README"
- File.exists?(file).should be_true
+ expect(File.exists?(file)).to be_true
end
it "logs status" do
- action(:remove_file, "doc/README").should == " remove doc/README\n"
+ expect(action(:remove_file, "doc/README")).to eq(" remove doc/README\n")
end
it "does not log status if required" do
- action(:remove_file, "doc/README", :verbose => false).should be_empty
+ expect(action(:remove_file, "doc/README", :verbose => false)).to be_empty
end
end
describe "#gsub_file" do
it "replaces the content in the file" do
action :gsub_file, "doc/README", "__start__", "START"
- File.binread(file).should == "START\nREADME\n__end__\n"
+ expect(File.binread(file)).to eq("START\nREADME\n__end__\n")
end
it "does not replace if pretending" do
runner(:pretend => true)
action :gsub_file, "doc/README", "__start__", "START"
- File.binread(file).should == "__start__\nREADME\n__end__\n"
+ expect(File.binread(file)).to eq("__start__\nREADME\n__end__\n")
end
it "accepts a block" do
action(:gsub_file, "doc/README", "__start__"){ |match| match.gsub('__', '').upcase }
- File.binread(file).should == "START\nREADME\n__end__\n"
+ expect(File.binread(file)).to eq("START\nREADME\n__end__\n")
end
it "logs status" do
- action(:gsub_file, "doc/README", "__start__", "START").should == " gsub doc/README\n"
+ expect(action(:gsub_file, "doc/README", "__start__", "START")).to eq(" gsub doc/README\n")
end
it "does not log status if required" do
- action(:gsub_file, file, "__", :verbose => false){ |match| match * 2 }.should be_empty
+ expect(action(:gsub_file, file, "__", :verbose => false){ |match| match * 2 }).to be_empty
end
end
describe "#append_to_file" do
it "appends content to the file" do
action :append_to_file, "doc/README", "END\n"
- File.binread(file).should == "__start__\nREADME\n__end__\nEND\n"
+ expect(File.binread(file)).to eq("__start__\nREADME\n__end__\nEND\n")
end
it "accepts a block" do
action(:append_to_file, "doc/README"){ "END\n" }
- File.binread(file).should == "__start__\nREADME\n__end__\nEND\n"
+ expect(File.binread(file)).to eq("__start__\nREADME\n__end__\nEND\n")
end
it "logs status" do
- action(:append_to_file, "doc/README", "END").should == " append doc/README\n"
+ expect(action(:append_to_file, "doc/README", "END")).to eq(" append doc/README\n")
end
end
describe "#prepend_to_file" do
it "prepends content to the file" do
action :prepend_to_file, "doc/README", "START\n"
- File.binread(file).should == "START\n__start__\nREADME\n__end__\n"
+ expect(File.binread(file)).to eq("START\n__start__\nREADME\n__end__\n")
end
it "accepts a block" do
action(:prepend_to_file, "doc/README"){ "START\n" }
- File.binread(file).should == "START\n__start__\nREADME\n__end__\n"
+ expect(File.binread(file)).to eq("START\n__start__\nREADME\n__end__\n")
end
it "logs status" do
- action(:prepend_to_file, "doc/README", "START").should == " prepend doc/README\n"
+ expect(action(:prepend_to_file, "doc/README", "START")).to eq(" prepend doc/README\n")
end
end
@@ -303,21 +303,21 @@ def file
it "appends content to a class" do
action :inject_into_class, "application.rb", Application, " filter_parameters :password\n"
- File.binread(file).should == "class Application < Base\n filter_parameters :password\nend\n"
+ expect(File.binread(file)).to eq("class Application < Base\n filter_parameters :password\nend\n")
end
it "accepts a block" do
action(:inject_into_class, "application.rb", Application){ " filter_parameters :password\n" }
- File.binread(file).should == "class Application < Base\n filter_parameters :password\nend\n"
+ expect(File.binread(file)).to eq("class Application < Base\n filter_parameters :password\nend\n")
end
it "logs status" do
- action(:inject_into_class, "application.rb", Application, " filter_parameters :password\n").should == " insert application.rb\n"
+ expect(action(:inject_into_class, "application.rb", Application, " filter_parameters :password\n")).to eq(" insert application.rb\n")
end
it "does not append if class name does not match" do
action :inject_into_class, "application.rb", "App", " filter_parameters :password\n"
- File.binread(file).should == "class Application < Base\nend\n"
+ expect(File.binread(file)).to eq("class Application < Base\nend\n")
end
end
end
@@ -336,41 +336,41 @@ def file
describe "#uncomment_lines" do
it "uncomments all matching lines in the file" do
action :uncomment_lines, "doc/COMMENTER", "green"
- File.binread(file).should =~ /__start__\n greenblue\n# yellowblue\n#yellowred\n greenred\norange\n purple\n ind#igo\n # ind#igo\n__end__/
+ expect(File.binread(file)).to match(/__start__\n greenblue\n# yellowblue\n#yellowred\n greenred\norange\n purple\n ind#igo\n # ind#igo\n__end__/)
action :uncomment_lines, "doc/COMMENTER", "red"
- File.binread(file).should =~ /__start__\n greenblue\n# yellowblue\nyellowred\n greenred\norange\n purple\n ind#igo\n # ind#igo\n__end__/
+ expect(File.binread(file)).to match(/__start__\n greenblue\n# yellowblue\nyellowred\n greenred\norange\n purple\n ind#igo\n # ind#igo\n__end__/)
end
it "correctly uncomments lines with hashes in them" do
action :uncomment_lines, "doc/COMMENTER", "ind#igo"
- File.binread(file).should =~ /__start__\n # greenblue\n# yellowblue\n#yellowred\n #greenred\norange\n purple\n ind#igo\n ind#igo\n__end__/
+ expect(File.binread(file)).to match(/__start__\n # greenblue\n# yellowblue\n#yellowred\n #greenred\norange\n purple\n ind#igo\n ind#igo\n__end__/)
end
it "does not modify already uncommented lines in the file" do
action :uncomment_lines, "doc/COMMENTER", "orange"
action :uncomment_lines, "doc/COMMENTER", "purple"
- File.binread(file).should =~ unmodified_comments_file
+ expect(File.binread(file)).to match(unmodified_comments_file)
end
end
describe "#comment_lines" do
it "comments lines which are not commented" do
action :comment_lines, "doc/COMMENTER", "orange"
- File.binread(file).should =~ /__start__\n # greenblue\n# yellowblue\n#yellowred\n #greenred\n# orange\n purple\n ind#igo\n # ind#igo\n__end__/
+ expect(File.binread(file)).to match(/__start__\n # greenblue\n# yellowblue\n#yellowred\n #greenred\n# orange\n purple\n ind#igo\n # ind#igo\n__end__/)
action :comment_lines, "doc/COMMENTER", "purple"
- File.binread(file).should =~ /__start__\n # greenblue\n# yellowblue\n#yellowred\n #greenred\n# orange\n # purple\n ind#igo\n # ind#igo\n__end__/
+ expect(File.binread(file)).to match(/__start__\n # greenblue\n# yellowblue\n#yellowred\n #greenred\n# orange\n # purple\n ind#igo\n # ind#igo\n__end__/)
end
it "correctly comments lines with hashes in them" do
action :comment_lines, "doc/COMMENTER", "ind#igo"
- File.binread(file).should =~ /__start__\n # greenblue\n# yellowblue\n#yellowred\n #greenred\norange\n purple\n # ind#igo\n # ind#igo\n__end__/
+ expect(File.binread(file)).to match(/__start__\n # greenblue\n# yellowblue\n#yellowred\n #greenred\norange\n purple\n # ind#igo\n # ind#igo\n__end__/)
end
it "does not modify already commented lines" do
action :comment_lines, "doc/COMMENTER", "green"
- File.binread(file).should =~ unmodified_comments_file
+ expect(File.binread(file)).to match(unmodified_comments_file)
end
end
end
36 spec/actions/inject_into_file_spec.rb
View
@@ -16,11 +16,11 @@ def revoker
end
def invoke!(*args, &block)
- capture(:stdout){ invoker.insert_into_file(*args, &block) }
+ capture(:stdout) { invoker.insert_into_file(*args, &block) }
end
def revoke!(*args, &block)
- capture(:stdout){ revoker.insert_into_file(*args, &block) }
+ capture(:stdout) { revoker.insert_into_file(*args, &block) }
end
def file
@@ -30,12 +30,12 @@ def file
describe "#invoke!" do
it "changes the file adding content after the flag" do
invoke! "doc/README", "\nmore content", :after => "__start__"
- File.read(file).should == "__start__\nmore content\nREADME\n__end__\n"
+ expect(File.read(file)).to eq("__start__\nmore content\nREADME\n__end__\n")
end
it "changes the file adding content before the flag" do
invoke! "doc/README", "more content\n", :before => "__end__"
- File.read(file).should == "__start__\nREADME\nmore content\n__end__\n"
+ expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n")
end
it "accepts data as a block" do
@@ -43,17 +43,17 @@ def file
"more content\n"
end
- File.read(file).should == "__start__\nREADME\nmore content\n__end__\n"
+ expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n")
end
it "logs status" do
- invoke!("doc/README", "\nmore content", :after => "__start__").should == " insert doc/README\n"
+ expect(invoke!("doc/README", "\nmore content", :after => "__start__")).to eq(" insert doc/README\n")
end
it "does not change the file if pretending" do
invoker :pretend => true
invoke! "doc/README", "\nmore content", :after => "__start__"
- File.read(file).should == "__start__\nREADME\n__end__\n"
+ expect(File.read(file)).to eq("__start__\nREADME\n__end__\n")
end
it "does not change the file if already include content" do
@@ -61,13 +61,13 @@ def file
"more content\n"
end
- File.read(file).should == "__start__\nREADME\nmore content\n__end__\n"
+ expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n")
invoke! "doc/README", :before => "__end__" do
"more content\n"
end
- File.read(file).should == "__start__\nREADME\nmore content\n__end__\n"
+ expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n")
end
it "does change the file if already include content and :force == true" do
@@ -75,13 +75,13 @@ def file
"more content\n"
end
- File.read(file).should == "__start__\nREADME\nmore content\n__end__\n"
+ expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n")
invoke! "doc/README", :before => "__end__", :force => true do
"more content\n"
end
- File.read(file).should == "__start__\nREADME\nmore content\nmore content\n__end__\n"
+ expect(File.read(file)).to eq("__start__\nREADME\nmore content\nmore content\n__end__\n")
end
end
@@ -90,46 +90,46 @@ def file
it "substracts the destination file after injection" do
invoke! "doc/README", "\nmore content", :after => "__start__"
revoke! "doc/README", "\nmore content", :after => "__start__"
- File.read(file).should == "__start__\nREADME\n__end__\n"
+ expect(File.read(file)).to eq("__start__\nREADME\n__end__\n")
end
it "substracts the destination file before injection" do
invoke! "doc/README", "more content\n", :before => "__start__"
revoke! "doc/README", "more content\n", :before => "__start__"
- File.read(file).should == "__start__\nREADME\n__end__\n"
+ expect(File.read(file)).to eq("__start__\nREADME\n__end__\n")
end
it "substracts even with double after injection" do
invoke! "doc/README", "\nmore content", :after => "__start__"
invoke! "doc/README", "\nanother stuff", :after => "__start__"
revoke! "doc/README", "\nmore content", :after => "__start__"
- File.read(file).should == "__start__\nanother stuff\nREADME\n__end__\n"
+ expect(File.read(file)).to eq("__start__\nanother stuff\nREADME\n__end__\n")
end
it "substracts even with double before injection" do
invoke! "doc/README", "more content\n", :before => "__start__"
invoke! "doc/README", "another stuff\n", :before => "__start__"
revoke! "doc/README", "more content\n", :before => "__start__"
- File.read(file).should == "another stuff\n__start__\nREADME\n__end__\n"
+ expect(File.read(file)).to eq("another stuff\n__start__\nREADME\n__end__\n")
end
it "substracts when prepending" do
invoke! "doc/README", "more content\n", :after => /\A/
invoke! "doc/README", "another stuff\n", :after => /\A/
revoke! "doc/README", "more content\n", :after => /\A/
- File.read(file).should == "another stuff\n__start__\nREADME\n__end__\n"
+ expect(File.read(file)).to eq("another stuff\n__start__\nREADME\n__end__\n")
end
it "substracts when appending" do
invoke! "doc/README", "more content\n", :before => /\z/
invoke! "doc/README", "another stuff\n", :before => /\z/
revoke! "doc/README", "more content\n", :before => /\z/
- File.read(file).should == "__start__\nREADME\n__end__\nanother stuff\n"
+ expect(File.read(file)).to eq("__start__\nREADME\n__end__\nanother stuff\n")
end
it "shows progress information to the user" do
invoke!("doc/README", "\nmore content", :after => "__start__")
- revoke!("doc/README", "\nmore content", :after => "__start__").should == " subtract doc/README\n"
+ expect(revoke!("doc/README", "\nmore content", :after => "__start__")).to eq(" subtract doc/README\n")
end
end
end
112 spec/actions_spec.rb
View
@@ -6,7 +6,7 @@ def runner(options={})
end
def action(*args, &block)
- capture(:stdout){ runner.send(*args, &block) }
+ capture(:stdout) { runner.send(*args, &block) }
end
def file
@@ -15,34 +15,34 @@ def file
describe "on include" do
it "adds runtime options to the base class" do
- MyCounter.class_options.keys.should include(:pretend)
- MyCounter.class_options.keys.should include(:force)
- MyCounter.class_options.keys.should include(:quiet)
- MyCounter.class_options.keys.should include(:skip)
+ expect(MyCounter.class_options.keys).to include(:pretend)
+ expect(MyCounter.class_options.keys).to include(:force)
+ expect(MyCounter.class_options.keys).to include(:quiet)
+ expect(MyCounter.class_options.keys).to include(:skip)
end
end
describe "#initialize" do
it "has default behavior invoke" do
- runner.behavior.should == :invoke
+ expect(runner.behavior).to eq(:invoke)
end
it "can have behavior revoke" do
- MyCounter.new([1], {}, :behavior => :revoke).behavior.should == :revoke
+ expect(MyCounter.new([1], {}, :behavior => :revoke).behavior).to eq(:revoke)
end
it "when behavior is set to force, overwrite options" do
runner = MyCounter.new([1], { :force => false, :skip => true }, :behavior => :force)
- runner.behavior.should == :invoke
- runner.options.force.should be_true
- runner.options.skip.should_not be_true
+ expect(runner.behavior).to eq(:invoke)
+ expect(runner.options.force).to be_true
+ expect(runner.options.skip).not_to be_true
end
it "when behavior is set to skip, overwrite options" do
runner = MyCounter.new([1], ["--force"], :behavior => :skip)
- runner.behavior.should == :invoke
- runner.options.force.should_not be_true
- runner.options.skip.should be_true
+ expect(runner.behavior).to eq(:invoke)
+ expect(runner.options.force).not_to be_true
+ expect(runner.options.skip).to be_true
end
end
@@ -51,82 +51,82 @@ def file
it "gets the current directory and expands the path to set the root" do
base = MyCounter.new([1])
base.destination_root = "here"
- base.destination_root.should == File.expand_path(File.join(File.dirname(__FILE__), "..", "here"))
+ expect(base.destination_root).to eq(File.expand_path(File.join(File.dirname(__FILE__), "..", "here")))
end
it "does not use the current directory if one is given" do
root = File.expand_path("/")
base = MyCounter.new([1])
base.destination_root = root
- base.destination_root.should == root
+ expect(base.destination_root).to eq(root)
end
it "uses the current directory if none is given" do
base = MyCounter.new([1])
- base.destination_root.should == File.expand_path(File.join(File.dirname(__FILE__), ".."))
+ expect(base.destination_root).to eq(File.expand_path(File.join(File.dirname(__FILE__), "..")))
end
end
describe "#relative_to_original_destination_root" do
it "returns the path relative to the absolute root" do
- runner.relative_to_original_destination_root(file).should == "foo"
+ expect(runner.relative_to_original_destination_root(file)).to eq("foo")
end
it "does not remove dot if required" do
- runner.relative_to_original_destination_root(file, false).should == "./foo"
+ expect(runner.relative_to_original_destination_root(file, false)).to eq("./foo")
end
it "always use the absolute root" do
runner.inside("foo") do
- runner.relative_to_original_destination_root(file).should == "foo"
+ expect(runner.relative_to_original_destination_root(file)).to eq("foo")
end
end
it "creates proper relative paths for absolute file location" do
- runner.relative_to_original_destination_root('/test/file').should == "/test/file"
+ expect(runner.relative_to_original_destination_root('/test/file')).to eq("/test/file")
end
it "does not fail with files constaining regexp characters" do
runner = MyCounter.new([1], {}, { :destination_root => File.join(destination_root, "fo[o-b]ar") })
- runner.relative_to_original_destination_root("bar").should == "bar"
+ expect(runner.relative_to_original_destination_root("bar")).to eq("bar")
end
describe "#source_paths_for_search" do
it "add source_root to source_paths_for_search" do
- MyCounter.source_paths_for_search.should include(File.expand_path("fixtures", File.dirname(__FILE__)))
+ expect(MyCounter.source_paths_for_search).to include(File.expand_path("fixtures", File.dirname(__FILE__)))
end
it "keeps only current source root in source paths" do
- ClearCounter.source_paths_for_search.should include(File.expand_path("fixtures/bundle", File.dirname(__FILE__)))
- ClearCounter.source_paths_for_search.should_not include(File.expand_path("fixtures", File.dirname(__FILE__)))
+ expect(ClearCounter.source_paths_for_search).to include(File.expand_path("fixtures/bundle", File.dirname(__FILE__)))
+ expect(ClearCounter.source_paths_for_search).not_to include(File.expand_path("fixtures", File.dirname(__FILE__)))
end
it "customized source paths should be before source roots" do
- ClearCounter.source_paths_for_search[0].should == File.expand_path("fixtures/doc", File.dirname(__FILE__))
- ClearCounter.source_paths_for_search[1].should == File.expand_path("fixtures/bundle", File.dirname(__FILE__))
+ expect(ClearCounter.source_paths_for_search[0]).to eq(File.expand_path("fixtures/doc", File.dirname(__FILE__)))
+ expect(ClearCounter.source_paths_for_search[1]).to eq(File.expand_path("fixtures/bundle", File.dirname(__FILE__)))
end
it "keeps inherited source paths at the end" do
- ClearCounter.source_paths_for_search.last.should == File.expand_path("fixtures/broken", File.dirname(__FILE__))
+ expect(ClearCounter.source_paths_for_search.last).to eq(File.expand_path("fixtures/broken", File.dirname(__FILE__)))
end
end
end
describe "#find_in_source_paths" do
it "raises an error if source path is empty" do
- lambda {
+ expect {
A.new.find_in_source_paths("foo")
- }.should raise_error(Thor::Error, /Currently you have no source paths/)
+ }.to raise_error(Thor::Error, /Currently you have no source paths/)
end
it "finds a template inside the source path" do
- runner.find_in_source_paths("doc").should == File.expand_path("doc", source_root)
- lambda { runner.find_in_source_paths("README") }.should raise_error
+ expect(runner.find_in_source_paths("doc")).to eq(File.expand_path("doc", source_root))
+ expect{ runner.find_in_source_paths("README") }.to raise_error
new_path = File.join(source_root, "doc")
runner.instance_variable_set(:@source_paths, nil)
runner.source_paths.unshift(new_path)
- runner.find_in_source_paths("README").should == File.expand_path("README", new_path)
+ expect(runner.find_in_source_paths("README")).to eq(File.expand_path("README", new_path))
end
end
end
@@ -134,49 +134,49 @@ def file
describe "#inside" do
it "executes the block inside the given folder" do
runner.inside("foo") do
- Dir.pwd.should == file
+ expect(Dir.pwd).to eq(file)
end
end
it "changes the base root" do
runner.inside("foo") do
- runner.destination_root.should == file
+ expect(runner.destination_root).to eq(file)
end
end
it "creates the directory if it does not exist" do
runner.inside("foo") do
- File.exists?(file).should be_true
+ expect(File.exists?(file)).to be_true
end
end
describe "when pretending" do
it "no directories should be created" do
runner.inside("bar", :pretend => true) {}
- File.exists?("bar").should be_false
+ expect(File.exists?("bar")).to be_false
end
end
describe "when verbose" do
it "logs status" do
- capture(:stdout) do
+ expect(capture(:stdout) {
runner.inside("foo", :verbose => true) {}
- end.should =~ /inside foo/
+ }).to match(/inside foo/)
end
it "uses padding in next status" do
- capture(:stdout) do
+ expect(capture(:stdout) {
runner.inside("foo", :verbose => true) do
runner.say_status :cool, :padding
end
- end.should =~ /cool padding/
+ }).to match(/cool padding/)
end
it "removes padding after block" do
- capture(:stdout) do
+ expect(capture(:stdout) {
runner.inside("foo", :verbose => true) {}
runner.say_status :no, :padding
- end.should =~ /no padding/
+ }).to match(/no padding/)
end
end
end
@@ -184,20 +184,20 @@ def file
describe "#in_root" do
it "executes the block in the root folder" do
runner.inside("foo") do
- runner.in_root { Dir.pwd.should == destination_root }
+ runner.in_root { expect(Dir.pwd).to eq(destination_root) }
end
end
it "changes the base root" do
runner.inside("foo") do
- runner.in_root { runner.destination_root.should == destination_root }
+ runner.in_root { expect(runner.destination_root).to eq(destination_root) }
end
end
it "returns to the previous state" do
runner.inside("foo") do
runner.in_root { }
- runner.destination_root.should == file
+ expect(runner.destination_root).to eq(file)
end
end
end
@@ -234,21 +234,21 @@ def file
it "opens a file and executes its content in the instance binding" do
action :apply, @file
- runner.instance_variable_get("@foo").should == "FOO"
+ expect(runner.instance_variable_get("@foo")).to eq("FOO")
end
it "applies padding to the content inside the file" do
- action(:apply, @file).should =~ /cool padding/
+ expect(action(:apply, @file)).to match(/cool padding/)
end
it "logs its status" do
- action(:apply, @file).should =~ / apply #{@file}\n/
+ expect(action(:apply, @file)).to match(/ apply #{@file}\n/)
end
it "does not log status" do
content = action(:apply, @file, :verbose => false)
- content.should =~ /cool padding/
- content.should_not =~ /apply http/
+ expect(content).to match(/cool padding/)
+ expect(content).not_to match(/apply http/)
end
end
@@ -262,11 +262,11 @@ def file
end
it "logs status" do
- action(:run, "ls").should == " run ls from \".\"\n"
+ expect(action(:run, "ls")).to eq(" run ls from \".\"\n")
end
it "does not log status if required" do
- action(:run, "ls", :verbose => false).should be_empty
+ expect(action(:run, "ls", :verbose => false)).to be_empty
end
it "accepts a color as status" do
@@ -286,11 +286,11 @@ def file
end
it "logs status" do
- action(:run_ruby_script, "script.rb").should == " run jruby script.rb from \".\"\n"
+ expect(action(:run_ruby_script, "script.rb")).to eq(" run jruby script.rb from \".\"\n")
end
it "does not log status if required" do
- action(:run_ruby_script, "script.rb", :verbose => false).should be_empty
+ expect(action(:run_ruby_script, "script.rb", :verbose => false)).to be_empty
end
end
@@ -315,12 +315,12 @@ def file
it "logs status" do
runner.should_receive(:system).with("thor list")
- action(:thor, :list).should == " run thor list from \".\"\n"
+ expect(action(:thor, :list)).to eq(" run thor list from \".\"\n")
end
it "does not log status if required" do
runner.should_receive(:system).with("thor list --foo 1 2 3")
- action(:thor, :list, :foo => [1,2,3], :verbose => false).should be_empty
+ expect(action(:thor, :list, :foo => [1,2,3], :verbose => false)).to be_empty
end
it "captures the output when :capture is given" do
138 spec/base_spec.rb
View
@@ -12,94 +12,94 @@ def hello
describe "#initialize" do
it "sets arguments array" do
base = MyCounter.new [1, 2]
- base.first.should == 1
- base.second.should == 2
+ expect(base.first).to eq(1)
+ expect(base.second).to eq(2)
end
it "sets arguments default values" do
base = MyCounter.new [1]
- base.second.should == 2
+ expect(base.second).to eq(2)
end
it "sets options default values" do
base = MyCounter.new [1, 2]
- base.options[:third].should == 3
+ expect(base.options[:third]).to eq(3)
end
it "allows options to be given as symbols or strings" do
base = MyCounter.new [1, 2], :third => 4
- base.options[:third].should == 4
+ expect(base.options[:third]).to eq(4)
base = MyCounter.new [1, 2], "third" => 4
- base.options[:third].should == 4
+ expect(base.options[:third]).to eq(4)
end
it "creates options with indifferent access" do
base = MyCounter.new [1, 2], :third => 3
- base.options['third'].should == 3
+ expect(base.options['third']).to eq(3)
end
it "creates options with magic predicates" do
base = MyCounter.new [1, 2], :third => 3
- base.options.third.should == 3
+ expect(base.options.third).to eq(3)
end
end
describe "#no_tasks" do
it "avoids methods being added as tasks" do
- MyScript.tasks.keys.should include("animal")
- MyScript.tasks.keys.should_not include("this_is_not_a_task")
+ expect(MyScript.tasks.keys).to include("animal")
+ expect(MyScript.tasks.keys).not_to include("this_is_not_a_task")
end
end
describe "#argument" do
it "sets a value as required and creates an accessor for it" do
- MyCounter.start(["1", "2", "--third", "3"])[0].should == 1
- Scripts::MyScript.start(["zoo", "my_special_param", "--param=normal_param"]).should == "my_special_param"
+ expect(MyCounter.start(["1", "2", "--third", "3"])[0]).to eq(1)
+ expect(Scripts::MyScript.start(["zoo", "my_special_param", "--param=normal_param"])).to eq("my_special_param")
end
it "does not set a value in the options hash" do
- BrokenCounter.start(["1", "2", "--third", "3"])[0].should be_nil
+ expect(BrokenCounter.start(["1", "2", "--third", "3"])[0]).to be_nil
end
end
describe "#arguments" do
it "returns the arguments for the class" do
- MyCounter.arguments.should have(2).items
+ expect(MyCounter.arguments).to have(2).items
end
end
describe "#class_option" do
it "sets options class wise" do
- MyCounter.start(["1", "2", "--third", "3"])[2].should == 3
+ expect(MyCounter.start(["1", "2", "--third", "3"])[2]).to eq(3)
end
it "does not create an accessor for it" do
- BrokenCounter.start(["1", "2", "--third", "3"])[3].should be_false
+ expect(BrokenCounter.start(["1", "2", "--third", "3"])[3]).to be_false
end
end
describe "#class_options" do
it "sets default options overwriting superclass definitions" do
options = Scripts::MyScript.class_options
- options[:force].should_not be_required
+ expect(options[:force]).not_to be_required
end
end
describe "#remove_argument" do
it "removes previous defined arguments from class" do
- ClearCounter.arguments.should be_empty
+ expect(ClearCounter.arguments).to be_empty
end
it "undefine accessors if required" do
- ClearCounter.new.should_not respond_to(:first)
- ClearCounter.new.should_not respond_to(:second)
+ expect(ClearCounter.new).not_to respond_to(:first)
+ expect(ClearCounter.new).not_to respond_to(:second)
end
end
describe "#remove_class_option" do
it "removes previous defined class option" do
- ClearCounter.class_options[:third].should be_nil
+ expect(ClearCounter.class_options[:third]).to be_nil
end
end
@@ -109,125 +109,125 @@ def hello
end
it "shows options description" do
- @content.should =~ /# The third argument/
+ expect(@content).to match(/# The third argument/)
end
it "shows usage with banner content" do
- @content.should =~ /\[\-\-third=THREE\]/
+ expect(@content).to match(/\[\-\-third=THREE\]/)
end
it "shows default values below description" do
- @content.should =~ /# Default: 3/
+ expect(@content).to match(/# Default: 3/)
end
it "shows options in different groups" do
- @content.should =~ /Options\:/
- @content.should =~ /Runtime options\:/
- @content.should =~ /\-p, \[\-\-pretend\]/
+ expect(@content).to match(/Options\:/)
+ expect(@content).to match(/Runtime options\:/)
+ expect(@content).to match(/\-p, \[\-\-pretend\]/)
end
it "use padding in options that does not have aliases" do
- @content.should =~ /^ -t, \[--third/
- @content.should =~ /^ \[--fourth/
+ expect(@content).to match(/^ -t, \[--third/)
+ expect(@content).to match(/^ \[--fourth/)
end
it "allows extra options to be given" do
hash = { "Foo" => B.class_options.values }
content = capture(:stdout) { MyCounter.send(:class_options_help, Thor::Base.shell.new, hash) }
- content.should =~ /Foo options\:/
- content.should =~ /--last-name=LAST_NAME/
+ expect(content).to match(/Foo options\:/)
+ expect(content).to match(/--last-name=LAST_NAME/)
end
it "displays choices for enums" do
content = capture(:stdout) { Enum.help(Thor::Base.shell.new) }
- content.should =~ /Possible values\: apple, banana/
+ expect(content).to match(/Possible values\: apple, banana/)
end
end
describe "#namespace" do
it "returns the default class namespace" do
- Scripts::MyScript.namespace.should == "scripts:my_script"
+ expect(Scripts::MyScript.namespace).to eq("scripts:my_script")
end
it "sets a namespace to the class" do
- Scripts::MyDefaults.namespace.should == "default"
+ expect(Scripts::MyDefaults.namespace).to eq("default")
end
end
describe "#group" do
it "sets a group" do
- MyScript.group.should == "script"
+ expect(MyScript.group).to eq("script")
end
it "inherits the group from parent" do
- MyChildScript.group.should == "script"
+ expect(MyChildScript.group).to eq("script")
end
it "defaults to standard if no group is given" do
- Amazing.group.should == "standard"
+ expect(Amazing.group).to eq("standard")
end
end
describe "#subclasses" do
it "tracks its subclasses in an Array" do
- Thor::Base.subclasses.should include(MyScript)
- Thor::Base.subclasses.should include(MyChildScript)
- Thor::Base.subclasses.should include(Scripts::MyScript)
+ expect(Thor::Base.subclasses).to include(MyScript)
+ expect(Thor::Base.subclasses).to include(MyChildScript)
+ expect(Thor::Base.subclasses).to include(Scripts::MyScript)
end
end
describe "#subclass_files" do
it "returns tracked subclasses, grouped by the files they come from" do
thorfile = File.join(File.dirname(__FILE__), "fixtures", "script.thor")
- Thor::Base.subclass_files[File.expand_path(thorfile)].should == [
+ expect(Thor::Base.subclass_files[File.expand_path(thorfile)]).to eq([
MyScript, MyScript::AnotherScript, MyChildScript, Barn,
Scripts::MyScript, Scripts::MyDefaults, Scripts::ChildDefault
- ]
+ ])
end
it "tracks a single subclass across multiple files" do
thorfile = File.join(File.dirname(__FILE__), "fixtures", "task.thor")
- Thor::Base.subclass_files[File.expand_path(thorfile)].should include(Amazing)
- Thor::Base.subclass_files[File.expand_path(__FILE__)].should include(Amazing)
+ expect(Thor::Base.subclass_files[File.expand_path(thorfile)]).to include(Amazing)
+ expect(Thor::Base.subclass_files[File.expand_path(__FILE__)]).to include(Amazing)
end
end
describe "#tasks" do
it "returns a list with all tasks defined in this class" do
- MyChildScript.new.should respond_to("animal")
- MyChildScript.tasks.keys.should include("animal")
+ expect(MyChildScript.new).to respond_to("animal")
+ expect(MyChildScript.tasks.keys).to include("animal")
end
it "raises an error if a task with reserved word is defined" do
- lambda {
+ expect {
klass = Class.new(Thor::Group)
klass.class_eval "def shell; end"
- }.should raise_error(RuntimeError, /"shell" is a Thor reserved word and cannot be defined as task/)
+ }.to raise_error(RuntimeError, /"shell" is a Thor reserved word and cannot be defined as task/)
end
end
describe "#all_tasks" do
it "returns a list with all tasks defined in this class plus superclasses" do
- MyChildScript.new.should respond_to("foo")
- MyChildScript.all_tasks.keys.should include("foo")
+ expect(MyChildScript.new).to respond_to("foo")
+ expect(MyChildScript.all_tasks.keys).to include("foo")
end
end
describe "#remove_task" do
it "removes the task from its tasks hash" do
- MyChildScript.tasks.keys.should_not include("bar")
- MyChildScript.tasks.keys.should_not include("boom")
+ expect(MyChildScript.tasks.keys).not_to include("bar")
+ expect(MyChildScript.tasks.keys).not_to include("boom")
end
it "undefines the method if desired" do
- MyChildScript.new.should_not respond_to("boom")
+ expect(MyChildScript.new).not_to respond_to("boom")
end
end
describe "#from_superclass" do
it "does not send a method to the superclass if the superclass does not respond to it" do
- MyCounter.get_from_super.should == 13
+ expect(MyCounter.get_from_super).to eq(13)
end
end
@@ -235,9 +235,9 @@ def hello
it "raises an error instead of rescueing if THOR_DEBUG=1 is given" do
begin
ENV["THOR_DEBUG"] = 1
- lambda {
+ expect {
MyScript.start ["what", "--debug"]
- }.should raise_error(Thor::UndefinedTaskError, 'Could not find task "what" in "my_script" namespace.')
+ }.to raise_error(Thor::UndefinedTaskError, 'Could not find task "what" in "my_script" namespace.')
rescue
ENV["THOR_DEBUG"] = nil
end
@@ -246,34 +246,34 @@ def hello
it "does not steal args" do
args = ["foo", "bar", "--force", "true"]
MyScript.start(args)
- args.should == ["foo", "bar", "--force", "true"]
+ expect(args).to eq(["foo", "bar", "--force", "true"])
end
it "checks unknown options" do
- capture(:stderr) {
+ expect(capture(:stderr) {
MyScript.start(["foo", "bar", "--force", "true", "--unknown", "baz"])
- }.strip.should == "Unknown switches '--unknown'"
+ }.strip).to eq("Unknown switches '--unknown'")
end
it "checks unknown options except specified" do
- capture(:stderr) {
- MyScript.start(["with_optional", "NAME", "--omg", "--invalid"]).should == ["NAME", {}, ["--omg", "--invalid"]]
- }.strip.should be_empty
+ expect(capture(:stderr) {
+ expect(MyScript.start(["with_optional", "NAME", "--omg", "--invalid"])).to eq(["NAME", {}, ["--omg", "--invalid"]])
+ }.strip).to be_empty
end
end
describe "attr_*" do
- it "should not add attr_reader as a task" do
- capture(:stderr){ MyScript.start(["another_attribute"]) }.should =~ /Could not find/
+ it "does not add attr_reader as a task" do
+ expect(capture(:stderr){ MyScript.start(["another_attribute"]) }).to match(/Could not find/)
end
- it "should not add attr_writer as a task" do
- capture(:stderr){ MyScript.start(["another_attribute=", "foo"]) }.should =~ /Could not find/
+ it "does not add attr_writer as a task" do
+ expect(capture(:stderr){ MyScript.start(["another_attribute=", "foo"]) }).to match(/Could not find/)
end
- it "should not add attr_accessor as a task" do
- capture(:stderr){ MyScript.start(["some_attribute"]) }.should =~ /Could not find/
- capture(:stderr){ MyScript.start(["some_attribute=", "foo"]) }.should =~ /Could not find/
+ it "does not add attr_accessor as a task" do
+ expect(capture(:stderr){ MyScript.start(["some_attribute"]) }).to match(/Could not find/)
+ expect(capture(:stderr){ MyScript.start(["some_attribute=", "foo"]) }).to match(/Could not find/)
end
end
end
28 spec/core_ext/hash_with_indifferent_access_spec.rb
View
@@ -7,37 +7,37 @@
end
it "has values accessible by either strings or symbols" do
- @hash['foo'].should == 'bar'
- @hash[:foo].should == 'bar'
+ expect(@hash['foo']).to eq('bar')
+ expect(@hash[:foo]).to eq('bar')
- @hash.values_at(:foo, :baz).should == ['bar', 'bee']
- @hash.delete(:foo).should == 'bar'
+ expect(@hash.values_at(:foo, :baz)).to eq(['bar', 'bee'])
+ expect(@hash.delete(:foo)).to eq('bar')
end
it "handles magic boolean predicates" do
- @hash.force?.should be_true
- @hash.foo?.should be_true
- @hash.nothing?.should be_false
+ expect(@hash.force?).to be_true
+ expect(@hash.foo?).to be_true
+ expect(@hash.nothing?).to be_false
end
it "handles magic comparisions" do
- @hash.foo?('bar').should be_true
- @hash.foo?('bee').should be_false
+ expect(@hash.foo?('bar')).to be_true
+ expect(@hash.foo?('bee')).to be_false
end
it "maps methods to keys" do
- @hash.foo.should == @hash['foo']
+ expect(@hash.foo).to eq(@hash['foo'])
end
it "merges keys independent if they are symbols or strings" do
@hash.merge!('force' => false, :baz => "boom")
- @hash[:force].should == false
- @hash[:baz].should == "boom"
+ expect(@hash[:force]).to eq(false)
+ expect(@hash[:baz]).to eq("boom")
end
it "creates a new hash by merging keys independent if they are symbols or strings" do
other = @hash.merge('force' => false, :baz => "boom")
- other[:force].should == false
- other[:baz].should == "boom"
+ expect(other[:force]).to eq(false)
+ expect(other[:baz]).to eq("boom")
end
end
58 spec/core_ext/ordered_hash_spec.rb
View
@@ -8,7 +8,7 @@
describe "without any items" do
it "returns nil for an undefined key" do
- @hash["foo"].should be_nil
+ expect(@hash["foo"]).to be_nil
end
it "doesn't iterate through any items" do
@@ -16,12 +16,12 @@
end
it "has an empty key and values list" do
- @hash.keys.should be_empty
- @hash.values.should be_empty
+ expect(@hash.keys).to be_empty
+ expect(@hash.values).to be_empty
end
it "must be empty" do
- @hash.should be_empty
+ expect(@hash).to be_empty
end
end
@@ -35,15 +35,15 @@
end
it "returns nil for an undefined key" do
- @hash[:boom].should be_nil
+ expect(@hash[:boom]).to be_nil
end
it "returns the value for each key" do
- @hash[:foo].should == "Foo!"
- @hash[:bar].should == "Bar!"
- @hash[:baz].should == "Baz!"
- @hash[:bop].should == "Bop!"
- @hash[:bat].should == "Bat!"
+ expect(@hash[:foo]).to eq("Foo!")
+ expect(@hash[:bar]).to eq("Bar!")
+ expect(@hash[:baz]).to eq("Baz!")
+ expect(@hash[:bop]).to eq("Bop!")
+ expect(@hash[:bat]).to eq("Bat!")
end
it "iterates through the keys and values in order of assignment" do
@@ -51,27 +51,27 @@
@hash.each do |key, value|
arr << [key, value]
end
- arr.should == [[:foo, "Foo!"], [:bar, "Bar!"], [:baz, "Baz!"],
- [:bop, "Bop!"], [:bat, "Bat!"]]
+ expect(arr).to eq([[:foo, "Foo!"], [:bar, "Bar!"], [:baz, "Baz!"],
+ [:bop, "Bop!"], [:bat, "Bat!"]])
end
it "returns the keys in order of insertion" do
- @hash.keys.should == [:foo, :bar, :baz, :bop, :bat]
+ expect(@hash.keys).to eq([:foo, :bar, :baz, :bop, :bat])
end
it "returns the values in order of insertion" do
- @hash.values.should == ["Foo!", "Bar!", "Baz!", "Bop!", "Bat!"]
+ expect(@hash.values).to eq(["Foo!", "Bar!", "Baz!", "Bop!", "Bat!"])
end
it "does not move an overwritten node to the end of the ordering" do
@hash[:baz] = "Bip!"
- @hash.values.should == ["Foo!", "Bar!", "Bip!", "Bop!", "Bat!"]
+ expect(@hash.values).to eq(["Foo!", "Bar!", "Bip!", "Bop!", "Bat!"])
@hash[:foo] = "Bip!"
- @hash.values.should == ["Bip!", "Bar!", "Bip!", "Bop!", "Bat!"]
+ expect(@hash.values).to eq(["Bip!", "Bar!", "Bip!", "Bop!", "Bat!"])
@hash[:bat] = "Bip!"
- @hash.values.should == ["Bip!", "Bar!", "Bip!", "Bop!", "Bip!"]
+ expect(@hash.values).to eq(["Bip!", "Bar!", "Bip!", "Bop!", "Bip!"])
end
it "appends another ordered hash while preserving ordering" do
@@ -79,37 +79,37 @@
other_hash[1] = "one"
other_hash[2] = "two"
other_hash[3] = "three"
- @hash.merge(other_hash).values.should == ["Foo!", "Bar!", "Baz!", "Bop!", "Bat!", "one", "two", "three"]
+ expect(@hash.merge(other_hash).values).to eq(["Foo!", "Bar!", "Baz!", "Bop!", "Bat!", "one", "two", "three"])
end
it "overwrites hash keys with matching appended keys" do
other_hash = Thor::CoreExt::OrderedHash.new
other_hash[:bar] = "bar"
- @hash.merge(other_hash)[:bar].should == "bar"
- @hash[:bar].should == "Bar!"
+ expect(@hash.merge(other_hash)[:bar]).to eq("bar")
+ expect(@hash[:bar]).to eq("Bar!")
end
it "converts to an array" do
- @hash.to_a.should == [[:foo, "Foo!"], [:bar, "Bar!"], [:baz, "Baz!"], [:bop, "Bop!"], [:bat, "Bat!"]]
+ expect(@hash.to_a).to eq([[:foo, "Foo!"], [:bar, "Bar!"], [:baz, "Baz!"], [:bop, "Bop!"], [:bat, "Bat!"]])
end
it "must not be empty" do
- @hash.should_not be_empty
+ expect(@hash).not_to be_empty
end
it "deletes values from hash" do
- @hash.delete(:baz).should == "Baz!"
- @hash.values.should == ["Foo!", "Bar!", "Bop!", "Bat!"]
+ expect(@hash.delete(:baz)).to eq("Baz!")
+ expect(@hash.values).to eq(["Foo!", "Bar!", "Bop!", "Bat!"])
- @hash.delete(:foo).should == "Foo!"
- @hash.values.should == ["Bar!", "Bop!", "Bat!"]
+ expect(@hash.delete(:foo)).to eq("Foo!")
+ expect(@hash.values).to eq(["Bar!", "Bop!", "Bat!"])
- @hash.delete(:bat).should == "Bat!"
- @hash.values.should == ["Bar!", "Bop!"]
+ expect(@hash.delete(:bat)).to eq("Bat!")
+ expect(@hash.values).to eq(["Bar!", "Bop!"])
end
it "returns nil if the value to be deleted can't be found" do
- @hash.delete(:nothing).should be_nil
+ expect(@hash.delete(:nothing)).to be_nil
end
end
end
6 spec/exit_condition_spec.rb
View
@@ -2,7 +2,7 @@
require 'thor/base'
describe "Exit conditions" do
- it "should exit 0, not bubble up EPIPE, if EPIPE is raised" do
+ it "exits 0, not bubble up EPIPE, if EPIPE is raised" do
epiped = false
task = Class.new(Thor) do
@@ -13,7 +13,7 @@
end
end
- lambda { task.start(["my_action"]) }.should raise_error(SystemExit)
- epiped.should == true
+ expect{ task.start(["my_action"]) }.to raise_error(SystemExit)
+ expect(epiped).to eq(true)
end
end
110 spec/group_spec.rb
View
@@ -3,36 +3,36 @@
describe Thor::Group do
describe "task" do
it "allows to use private methods from parent class as tasks" do
- ChildGroup.start.should == ["bar", "foo", "baz"]
- ChildGroup.new.baz("bar").should == "bar"
+ expect(ChildGroup.start).to eq(["bar", "foo", "baz"])
+ expect(ChildGroup.new.baz("bar")).to eq("bar")
end
end
describe "#start" do
it "invokes all the tasks under the Thor group" do
- MyCounter.start(["1", "2", "--third", "3"]).should == [ 1, 2, 3 ]
+ expect(MyCounter.start(["1", "2", "--third", "3"])).to eq([ 1, 2, 3 ])
end
it "uses argument default value" do
- MyCounter.start(["1", "--third", "3"]).should == [ 1, 2, 3 ]
+ expect(MyCounter.start(["1", "--third", "3"])).to eq([ 1, 2, 3 ])
end
it "invokes all the tasks in the Thor group and his parents" do
- BrokenCounter.start(["1", "2", "--third", "3"]).should == [ nil, 2, 3, false, 5 ]
+ expect(BrokenCounter.start(["1", "2", "--third", "3"])).to eq([ nil, 2, 3, false, 5 ])
end
it "raises an error if a required argument is added after a non-required" do
- lambda {
+ expect {
MyCounter.argument(:foo, :type => :string)
- }.should raise_error(ArgumentError, 'You cannot have "foo" as required argument after the non-required argument "second".')
+ }.to raise_error(ArgumentError, 'You cannot have "foo" as required argument after the non-required argument "second".')
end
it "raises when an exception happens within the task call" do
- lambda { BrokenCounter.start(["1", "2", "--fail"]) }.should raise_error
+ expect{ BrokenCounter.start(["1", "2", "--fail"]) }.to raise_error
end
it "raises an error when a Thor group task expects arguments" do
- lambda { WhinyGenerator.start }.should raise_error(ArgumentError, /thor wrong_arity takes 1 argument, but it should not/)
+ expect{ WhinyGenerator.start }.to raise_error(ArgumentError, /thor wrong_arity takes 1 argument, but it should not/)
end
it "invokes help message if any of the shortcuts is given" do