From 35b14a9ff7d72531f740a4abb1c2587c033afd3f Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Fri, 19 Nov 2010 12:36:08 -0800 Subject: [PATCH] Add rcov to bundle --- Gemfile | 1 + Gemfile.lock | 2 + Thorfile | 1 + spec/actions/create_file_spec.rb | 54 +++---- spec/actions/directory_spec.rb | 44 +++--- spec/actions/empty_directory_spec.rb | 22 +-- spec/actions/file_manipulation_spec.rb | 72 +++++----- spec/actions/inject_into_file_spec.rb | 32 ++--- spec/actions_spec.rb | 98 ++++++------- spec/base_spec.rb | 120 ++++++++-------- .../hash_with_indifferent_access_spec.rb | 28 ++-- spec/core_ext/ordered_hash_spec.rb | 56 ++++---- spec/group_spec.rb | 78 +++++----- spec/invocation_spec.rb | 42 +++--- spec/parser/argument_spec.rb | 14 +- spec/parser/arguments_spec.rb | 22 +-- spec/parser/option_spec.rb | 90 ++++++------ spec/parser/options_spec.rb | 134 +++++++++--------- spec/rake_compat_spec.rb | 18 +-- spec/register_spec.rb | 10 +- spec/runner_spec.rb | 64 ++++----- spec/shell/basic_spec.rb | 36 ++--- spec/shell/color_spec.rb | 6 +- spec/shell_spec.rb | 14 +- spec/spec_helper.rb | 7 +- spec/task_spec.rb | 16 +-- spec/thor_spec.rb | 124 ++++++++-------- spec/util_spec.rb | 70 ++++----- 28 files changed, 638 insertions(+), 637 deletions(-) diff --git a/Gemfile b/Gemfile index 36ee16f6d..b4c44f0aa 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source 'http://rubygems.org' gem 'fakeweb' +gem 'rcov' gem 'rspec' gem 'diff-lcs' gem 'jeweler' diff --git a/Gemfile.lock b/Gemfile.lock index de107435b..9277115c7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -14,6 +14,7 @@ GEM linecache19 (0.5.11) ruby_core_source (>= 0.1.4) rake (0.8.7) + rcov (0.9.9) rdoc (2.5.11) rspec (2.1.0) rspec-core (~> 2.1.0) @@ -48,6 +49,7 @@ DEPENDENCIES fakeweb jeweler rake + rcov rdoc rspec ruby-debug (>= 0.10.3) diff --git a/Thorfile b/Thorfile index 2157cc1c3..511390eee 100644 --- a/Thorfile +++ b/Thorfile @@ -14,6 +14,7 @@ class Default < Thor RSpec::Core::RakeTask.new(:rcov) do |t| t.rcov = true + t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*"] end begin diff --git a/spec/actions/create_file_spec.rb b/spec/actions/create_file_spec.rb index cbb7428d0..271d52184 100644 --- a/spec/actions/create_file_spec.rb +++ b/spec/actions/create_file_spec.rb @@ -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")).must be_true + File.exists?(File.join(destination_root, "doc/config.rb")).should 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")).must be_false + File.exists?(File.join(destination_root, "doc/config.rb")).should be_false end it "shows created status to the user" do create_file("doc/config.rb") - invoke!.must == " create doc/config.rb\n" + invoke!.should == " 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!.must be_empty + invoke!.should be_empty end it "returns the given destination" do capture(:stdout) do - create_file("doc/config.rb").invoke!.must == "doc/config.rb" + create_file("doc/config.rb").invoke!.should == "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")).must be_true + File.exists?(File.join(destination_root, "doc/rdoc.rb.tt")).should 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!.must == " identical doc/config.rb\n" + invoke!.should == " 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).must_not be_identical - invoke!.must == " force doc/config.rb\n" + create_file("doc/config.rb", {}, :force => true).should_not be_identical + invoke!.should == " 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).must_not be_identical - invoke!.must == " skip doc/config.rb\n" + create_file("doc/config.rb", {}, :skip => true).should_not be_identical + invoke!.should == " 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).must_not be_identical - invoke!.must == " force doc/config.rb\n" + create_file("doc/config.rb", :force => true).should_not be_identical + invoke!.should == " 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).must_not be_identical - invoke!.must == " skip doc/config.rb\n" + create_file("doc/config.rb", :skip => true).should_not be_identical + invoke!.should == " skip doc/config.rb\n" end it "shows conflict status to ther user" do - create_file("doc/config.rb").must_not be_identical + create_file("doc/config.rb").should_not be_identical $stdin.should_receive(:gets).and_return('s') file = File.join(destination_root, 'doc/config.rb') content = invoke! - content.must =~ /conflict doc\/config\.rb/ - content.must =~ /Overwrite #{file}\? \(enter "h" for help\) \[Ynaqdh\]/ - content.must =~ /skip doc\/config\.rb/ + content.should =~ /conflict doc\/config\.rb/ + content.should =~ /Overwrite #{file}\? \(enter "h" for help\) \[Ynaqdh\]/ + content.should =~ /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!.must =~ /force doc\/config\.rb/ + invoke!.should =~ /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!.must =~ /skip doc\/config\.rb/ + invoke!.should =~ /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).must be_false + File.exists?(@action.destination).should 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).must be_false + File.exists?(@action.destination).should be_false end end describe "#exists?" do it "returns true if the destination file exists" do create_file("doc/config.rb") - @action.exists?.must be_false + @action.exists?.should be_false invoke! - @action.exists?.must be_true + @action.exists?.should 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?.must be_false + @action.identical?.should be_false invoke! - @action.identical?.must be_true + @action.identical?.should be_true end end end diff --git a/spec/actions/directory_spec.rb b/spec/actions/directory_spec.rb index 8cd482a9e..e15595ca0 100644 --- a/spec/actions/directory_spec.rb +++ b/spec/actions/directory_spec.rb @@ -28,8 +28,8 @@ 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).must be_true - FileUtils.identical?(source, destination).must be_true + File.exists?(destination).should be_true + FileUtils.identical?(source, destination).should be_true end end @@ -37,12 +37,12 @@ def exists_and_identical?(source_path, destination_path) it "raises an error if the source does not exist" do lambda { invoke! "unknown" - }.must raise_error(Thor::Error, /Could not find "unknown" in any of your source paths/) + }.should 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 invoke! "doc", "ghost", :pretend => true - File.exists?("ghost").must be_false + File.exists?("ghost").should 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).must be_true + File.exists?(file).should be_true file = File.join(destination_root, "tasks", "doc") - File.exists?(file).must be_false + File.exists?(file).should be_false file = File.join(destination_root, "tasks", "doc", "README") - File.exists?(file).must be_false + File.exists?(file).should be_false end it "copies files from the source relative to the current path" do @@ -78,40 +78,40 @@ 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).must be_true - File.read(file).must == "FOO = FOO\n" + File.exists?(file).should be_true + File.read(file).should == "FOO = FOO\n" end it "copies directories" do invoke! "doc", "docs" file = File.join(destination_root, "docs", "components") - File.exists?(file).must be_true - File.directory?(file).must be_true + File.exists?(file).should be_true + File.directory?(file).should 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).must be_false + File.exists?(file).should 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).must be_true + File.exists?(file).should be_true end it "does not copy empty directories twice" do content = invoke!("doc/components", "docs/components") - content.must_not =~ /exist/ + content.should_not =~ /exist/ end it "logs status" do content = invoke!("doc") - content.must =~ /create doc\/README/ - content.must =~ /create doc\/config\.rb/ - content.must =~ /create doc\/rdoc\.rb/ - content.must =~ /create doc\/components/ + content.should =~ /create doc\/README/ + content.should =~ /create doc\/config\.rb/ + content.should =~ /create doc\/rdoc\.rb/ + content.should =~ /create doc\/components/ end it "yields a block" do @@ -119,7 +119,7 @@ def exists_and_identical?(source_path, destination_path) invoke!("doc") do |content| checked ||= !!(content =~ /FOO/) end - checked.must be_true + checked.should be_true end end @@ -128,9 +128,9 @@ def exists_and_identical?(source_path, destination_path) invoke! "doc" revoke! "doc" - File.exists?(File.join(destination_root, "doc", "README")).must be_false - File.exists?(File.join(destination_root, "doc", "config.rb")).must be_false - File.exists?(File.join(destination_root, "doc", "components")).must be_false + 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 end end end diff --git a/spec/actions/empty_directory_spec.rb b/spec/actions/empty_directory_spec.rb index c4def4ee4..dedc40ede 100644 --- a/spec/actions/empty_directory_spec.rb +++ b/spec/actions/empty_directory_spec.rb @@ -24,12 +24,12 @@ def base describe "#destination" do it "returns the full destination with the destination_root" do - empty_directory('doc').destination.must == File.join(destination_root, 'doc') + empty_directory('doc').destination.should == File.join(destination_root, 'doc') end it "takes relative root into account" do base.inside('doc') do - empty_directory('contents').destination.must == File.join(destination_root, 'doc', 'contents') + empty_directory('contents').destination.should == 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.must == 'doc/contents' + empty_directory('contents').relative_destination.should == '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.must == 'contents' + empty_directory('contents').given_destination.should == '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")).must be_true + File.exists?(File.join(destination_root, "doc")).should be_true end it "shows created status to the user" do empty_directory("doc") - invoke!.must == " create doc\n" + invoke!.should == " 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")).must be_false + File.exists?(File.join(base.destination_root, "ghost")).should be_false end describe "when directory exists" do it "shows exist status" do empty_directory("doc") invoke! - invoke!.must == " exist doc\n" + invoke!.should == " exist doc\n" end end end @@ -83,16 +83,16 @@ def base empty_directory("doc") invoke! revoke! - File.exists?(@action.destination).must be_false + File.exists?(@action.destination).should be_false end end describe "#exists?" do it "returns true if the destination file exists" do empty_directory("doc") - @action.exists?.must be_false + @action.exists?.should be_false invoke! - @action.exists?.must be_true + @action.exists?.should be_true end end end diff --git a/spec/actions/file_manipulation_spec.rb b/spec/actions/file_manipulation_spec.rb index 6668bf902..f4a6a4f7c 100644 --- a/spec/actions/file_manipulation_spec.rb +++ b/spec/actions/file_manipulation_spec.rb @@ -13,10 +13,10 @@ def action(*args, &block) def exists_and_identical?(source, destination) destination = File.join(destination_root, destination) - File.exists?(destination).must be_true + File.exists?(destination).should be_true source = File.join(source_root, source) - FileUtils.must be_identical(source, destination) + FileUtils.should 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).must == " chmod foo\n" + action(:chmod, "foo", 0755).should == " 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).must be_empty + action(:chmod, "foo", 0755, :verbose => false).should be_empty end end @@ -69,14 +69,14 @@ def file end it "logs status" do - action(:copy_file, "task.thor").must == " create task.thor\n" + action(:copy_file, "task.thor").should == " 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")).must =~ /^OMG/ + File.read(File.join(destination_root, "task.thor")).should =~ /^OMG/ end end @@ -98,19 +98,19 @@ def file it "yields file content to a block" do action :get, "doc/README" do |content| - content.must == "__start__\nREADME\n__end__\n" + content.should == "__start__\nREADME\n__end__\n" end end it "logs status" do - action(:get, "doc/README", "docs/README").must == " create docs/README\n" + action(:get, "doc/README", "docs/README").should == " 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.must == body + content.should == body end FakeWeb.clean_registry end @@ -119,7 +119,7 @@ def file 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.must == body + content.should == body end FakeWeb.clean_registry end @@ -130,7 +130,7 @@ def file action :template, "doc/block_helper.rb" file = File.join(destination_root, "doc/block_helper.rb") - File.read(file).must == "Hello world!" + File.read(file).should == "Hello world!" end it "evaluates the template given as source" do @@ -138,31 +138,31 @@ def file action :template, "doc/config.rb" file = File.join(destination_root, "doc/config.rb") - File.read(file).must == "class Config; end\n" + File.read(file).should == "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).must be_true + File.exists?(file).should 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.tt") - File.exists?(file).must be_true + File.exists?(file).should be_true end it "logs status" do - capture(:stdout){ runner.template("doc/config.rb") }.must == " create doc/config.rb\n" + capture(:stdout){ runner.template("doc/config.rb") }.should == " 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")).must =~ /^OMG/ + File.read(File.join(destination_root, "doc/config.rb")).should =~ /^OMG/ end end @@ -178,84 +178,84 @@ def file describe "#remove_file" do it "removes the file given" do action :remove_file, "doc/README" - File.exists?(file).must be_false + File.exists?(file).should be_false end it "removes directories too" do action :remove_dir, "doc" - File.exists?(File.join(destination_root, "doc")).must be_false + File.exists?(File.join(destination_root, "doc")).should be_false end it "does not remove if pretending" do runner(:pretend => true) action :remove_file, "doc/README" - File.exists?(file).must be_true + File.exists?(file).should be_true end it "logs status" do - action(:remove_file, "doc/README").must == " remove doc/README\n" + action(:remove_file, "doc/README").should == " remove doc/README\n" end it "does not log status if required" do - action(:remove_file, "doc/README", :verbose => false).must be_empty + action(:remove_file, "doc/README", :verbose => false).should 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).must == "START\nREADME\n__end__\n" + File.binread(file).should == "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).must == "__start__\nREADME\n__end__\n" + File.binread(file).should == "__start__\nREADME\n__end__\n" end it "accepts a block" do action(:gsub_file, "doc/README", "__start__"){ |match| match.gsub('__', '').upcase } - File.binread(file).must == "START\nREADME\n__end__\n" + File.binread(file).should == "START\nREADME\n__end__\n" end it "logs status" do - action(:gsub_file, "doc/README", "__start__", "START").must == " gsub doc/README\n" + action(:gsub_file, "doc/README", "__start__", "START").should == " gsub doc/README\n" end it "does not log status if required" do - action(:gsub_file, file, "__", :verbose => false){ |match| match * 2 }.must be_empty + action(:gsub_file, file, "__", :verbose => false){ |match| match * 2 }.should 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).must == "__start__\nREADME\n__end__\nEND\n" + File.binread(file).should == "__start__\nREADME\n__end__\nEND\n" end it "accepts a block" do action(:append_to_file, "doc/README"){ "END\n" } - File.binread(file).must == "__start__\nREADME\n__end__\nEND\n" + File.binread(file).should == "__start__\nREADME\n__end__\nEND\n" end it "logs status" do - action(:append_to_file, "doc/README", "END").must == " append doc/README\n" + action(:append_to_file, "doc/README", "END").should == " 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).must == "START\n__start__\nREADME\n__end__\n" + File.binread(file).should == "START\n__start__\nREADME\n__end__\n" end it "accepts a block" do action(:prepend_to_file, "doc/README"){ "START\n" } - File.binread(file).must == "START\n__start__\nREADME\n__end__\n" + File.binread(file).should == "START\n__start__\nREADME\n__end__\n" end it "logs status" do - action(:prepend_to_file, "doc/README", "START").must == " prepend doc/README\n" + action(:prepend_to_file, "doc/README", "START").should == " prepend doc/README\n" end end @@ -266,21 +266,21 @@ def file it "appends content to a class" do action :inject_into_class, "application.rb", Application, " filter_parameters :password\n" - File.binread(file).must == "class Application < Base\n filter_parameters :password\nend\n" + File.binread(file).should == "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).must == "class Application < Base\n filter_parameters :password\nend\n" + File.binread(file).should == "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").must == " insert application.rb\n" + action(:inject_into_class, "application.rb", Application, " filter_parameters :password\n").should == " 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).must == "class Application < Base\nend\n" + File.binread(file).should == "class Application < Base\nend\n" end end end diff --git a/spec/actions/inject_into_file_spec.rb b/spec/actions/inject_into_file_spec.rb index d4e345fd9..90e3c71cb 100644 --- a/spec/actions/inject_into_file_spec.rb +++ b/spec/actions/inject_into_file_spec.rb @@ -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).must == "__start__\nmore content\nREADME\n__end__\n" + File.read(file).should == "__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).must == "__start__\nREADME\nmore content\n__end__\n" + File.read(file).should == "__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).must == "__start__\nREADME\nmore content\n__end__\n" + File.read(file).should == "__start__\nREADME\nmore content\n__end__\n" end it "logs status" do - invoke!("doc/README", "\nmore content", :after => "__start__").must == " insert doc/README\n" + invoke!("doc/README", "\nmore content", :after => "__start__").should == " 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).must == "__start__\nREADME\n__end__\n" + File.read(file).should == "__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).must == "__start__\nREADME\nmore content\n__end__\n" + File.read(file).should == "__start__\nREADME\nmore content\n__end__\n" invoke! "doc/README", :before => "__end__" do "more content\n" end - File.read(file).must == "__start__\nREADME\nmore content\n__end__\n" + File.read(file).should == "__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).must == "__start__\nREADME\nmore content\n__end__\n" + File.read(file).should == "__start__\nREADME\nmore content\n__end__\n" invoke! "doc/README", :before => "__end__", :force => true do "more content\n" end - File.read(file).must == "__start__\nREADME\nmore content\nmore content\n__end__\n" + File.read(file).should == "__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).must == "__start__\nREADME\n__end__\n" + File.read(file).should == "__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).must == "__start__\nREADME\n__end__\n" + File.read(file).should == "__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).must == "__start__\nanother stuff\nREADME\n__end__\n" + File.read(file).should == "__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).must == "another stuff\n__start__\nREADME\n__end__\n" + File.read(file).should == "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).must == "another stuff\n__start__\nREADME\n__end__\n" + File.read(file).should == "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).must == "__start__\nREADME\n__end__\nanother stuff\n" + File.read(file).should == "__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__").must == " subtract doc/README\n" + revoke!("doc/README", "\nmore content", :after => "__start__").should == " subtract doc/README\n" end end end diff --git a/spec/actions_spec.rb b/spec/actions_spec.rb index d580036bc..f523ee133 100644 --- a/spec/actions_spec.rb +++ b/spec/actions_spec.rb @@ -15,34 +15,34 @@ def file describe "on include" do it "adds runtime options to the base class" do - MyCounter.class_options.keys.must include(:pretend) - MyCounter.class_options.keys.must include(:force) - MyCounter.class_options.keys.must include(:quiet) - MyCounter.class_options.keys.must include(:skip) + 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) end end describe "#initialize" do it "has default behavior invoke" do - runner.behavior.must == :invoke + runner.behavior.should == :invoke end it "can have behavior revoke" do - MyCounter.new([1], {}, :behavior => :revoke).behavior.must == :revoke + MyCounter.new([1], {}, :behavior => :revoke).behavior.should == :revoke end it "when behavior is set to force, overwrite options" do runner = MyCounter.new([1], { :force => false, :skip => true }, :behavior => :force) - runner.behavior.must == :invoke - runner.options.force.must be_true - runner.options.skip.must_not be_true + runner.behavior.should == :invoke + runner.options.force.should be_true + runner.options.skip.should_not be_true end it "when behavior is set to skip, overwrite options" do runner = MyCounter.new([1], ["--force"], :behavior => :skip) - runner.behavior.must == :invoke - runner.options.force.must_not be_true - runner.options.skip.must be_true + runner.behavior.should == :invoke + runner.options.force.should_not be_true + runner.options.skip.should be_true end end @@ -51,54 +51,54 @@ 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.must == File.expand_path(File.join(File.dirname(__FILE__), "..", "here")) + base.destination_root.should == 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.must == root + base.destination_root.should == root end it "uses the current directory if none is given" do base = MyCounter.new([1]) - base.destination_root.must == File.expand_path(File.join(File.dirname(__FILE__), "..")) + base.destination_root.should == 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).must == "foo" + runner.relative_to_original_destination_root(file).should == "foo" end it "does not remove dot if required" do - runner.relative_to_original_destination_root(file, false).must == "./foo" + runner.relative_to_original_destination_root(file, false).should == "./foo" end it "always use the absolute root" do runner.inside("foo") do - runner.relative_to_original_destination_root(file).must == "foo" + runner.relative_to_original_destination_root(file).should == "foo" end end describe "#source_paths_for_search" do it "add source_root to source_paths_for_search" do - MyCounter.source_paths_for_search.must include(File.expand_path("fixtures", File.dirname(__FILE__))) + MyCounter.source_paths_for_search.should include(File.expand_path("fixtures", File.dirname(__FILE__))) end it "keeps only current source root in source paths" do - ClearCounter.source_paths_for_search.must include(File.expand_path("fixtures/bundle", File.dirname(__FILE__))) - ClearCounter.source_paths_for_search.must_not include(File.expand_path("fixtures", File.dirname(__FILE__))) + 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__))) end it "customized source paths should be before source roots" do - ClearCounter.source_paths_for_search[0].must == File.expand_path("fixtures/doc", File.dirname(__FILE__)) - ClearCounter.source_paths_for_search[1].must == File.expand_path("fixtures/bundle", File.dirname(__FILE__)) + 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__)) end it "keeps inherited source paths at the end" do - ClearCounter.source_paths_for_search.last.must == File.expand_path("fixtures/broken", File.dirname(__FILE__)) + ClearCounter.source_paths_for_search.last.should == File.expand_path("fixtures/broken", File.dirname(__FILE__)) end end end @@ -107,17 +107,17 @@ def file it "raises an error if source path is empty" do lambda { A.new.find_in_source_paths("foo") - }.must raise_error(Thor::Error, /Currently you have no source paths/) + }.should 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").must == File.expand_path("doc", source_root) - lambda { runner.find_in_source_paths("README") }.must raise_error + runner.find_in_source_paths("doc").should == File.expand_path("doc", source_root) + lambda { runner.find_in_source_paths("README") }.should 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").must == File.expand_path("README", new_path) + runner.find_in_source_paths("README").should == File.expand_path("README", new_path) end end end @@ -125,26 +125,26 @@ def file describe "#inside" do it "executes the block inside the given folder" do runner.inside("foo") do - Dir.pwd.must == file + Dir.pwd.should == file end end it "changes the base root" do runner.inside("foo") do - runner.destination_root.must == file + runner.destination_root.should == file end end it "creates the directory if it does not exist" do runner.inside("foo") do - File.exists?(file).must be_true + File.exists?(file).should be_true end end describe "when pretending" do it "no directories should be created" do runner.inside("bar", :pretend => true) {} - File.exists?("bar").must be_false + File.exists?("bar").should be_false end end @@ -152,7 +152,7 @@ def file it "logs status" do capture(:stdout) do runner.inside("foo", :verbose => true) {} - end.must =~ /inside foo/ + end.should =~ /inside foo/ end it "uses padding in next status" do @@ -160,14 +160,14 @@ def file runner.inside("foo", :verbose => true) do runner.say_status :cool, :padding end - end.must =~ /cool padding/ + end.should =~ /cool padding/ end it "removes padding after block" do capture(:stdout) do runner.inside("foo", :verbose => true) {} runner.say_status :no, :padding - end.must =~ /no padding/ + end.should =~ /no padding/ end end end @@ -175,20 +175,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.must == destination_root } + runner.in_root { Dir.pwd.should == destination_root } end end it "changes the base root" do runner.inside("foo") do - runner.in_root { runner.destination_root.must == destination_root } + runner.in_root { runner.destination_root.should == destination_root } end end it "returns to the previous state" do runner.inside("foo") do runner.in_root { } - runner.destination_root.must == file + runner.destination_root.should == file end end end @@ -225,21 +225,21 @@ def file it "opens a file and executes its content in the instance binding" do action :apply, @file - runner.instance_variable_get("@foo").must == "FOO" + runner.instance_variable_get("@foo").should == "FOO" end it "applies padding to the content inside the file" do - action(:apply, @file).must =~ /cool padding/ + action(:apply, @file).should =~ /cool padding/ end it "logs its status" do - action(:apply, @file).must =~ / apply #{@file}\n/ + action(:apply, @file).should =~ / apply #{@file}\n/ end it "does not log status" do content = action(:apply, @file, :verbose => false) - content.must =~ /cool padding/ - content.must_not =~ /apply http/ + content.should =~ /cool padding/ + content.should_not =~ /apply http/ end end @@ -253,11 +253,11 @@ def file end it "logs status" do - action(:run, "ls").must == " run ls from \".\"\n" + action(:run, "ls").should == " run ls from \".\"\n" end it "does not log status if required" do - action(:run, "ls", :verbose => false).must be_empty + action(:run, "ls", :verbose => false).should be_empty end it "accepts a color as status" do @@ -277,11 +277,11 @@ def file end it "logs status" do - action(:run_ruby_script, "script.rb").must == " run jruby script.rb from \".\"\n" + action(:run_ruby_script, "script.rb").should == " run jruby script.rb from \".\"\n" end it "does not log status if required" do - action(:run_ruby_script, "script.rb", :verbose => false).must be_empty + action(:run_ruby_script, "script.rb", :verbose => false).should be_empty end end @@ -306,12 +306,12 @@ def file it "logs status" do runner.should_receive(:system).with("thor list") - action(:thor, :list).must == " run thor list from \".\"\n" + action(:thor, :list).should == " 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).must be_empty + action(:thor, :list, :foo => [1,2,3], :verbose => false).should be_empty end it "captures the output when :capture is given" do diff --git a/spec/base_spec.rb b/spec/base_spec.rb index 236d86e25..9b8dda1ed 100644 --- a/spec/base_spec.rb +++ b/spec/base_spec.rb @@ -12,94 +12,94 @@ def hello describe "#initialize" do it "sets arguments array" do base = MyCounter.new [1, 2] - base.first.must == 1 - base.second.must == 2 + base.first.should == 1 + base.second.should == 2 end it "sets arguments default values" do base = MyCounter.new [1] - base.second.must == 2 + base.second.should == 2 end it "sets options default values" do base = MyCounter.new [1, 2] - base.options[:third].must == 3 + base.options[:third].should == 3 end it "allows options to be given as symbols or strings" do base = MyCounter.new [1, 2], :third => 4 - base.options[:third].must == 4 + base.options[:third].should == 4 base = MyCounter.new [1, 2], "third" => 4 - base.options[:third].must == 4 + base.options[:third].should == 4 end it "creates options with indifferent access" do base = MyCounter.new [1, 2], :third => 3 - base.options['third'].must == 3 + base.options['third'].should == 3 end it "creates options with magic predicates" do base = MyCounter.new [1, 2], :third => 3 - base.options.third.must == 3 + base.options.third.should == 3 end end describe "#no_tasks" do it "avoids methods being added as tasks" do - MyScript.tasks.keys.must include("animal") - MyScript.tasks.keys.must_not include("this_is_not_a_task") + MyScript.tasks.keys.should include("animal") + MyScript.tasks.keys.should_not 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].must == 1 - Scripts::MyScript.start(["zoo", "my_special_param", "--param=normal_param"]).must == "my_special_param" + MyCounter.start(["1", "2", "--third", "3"])[0].should == 1 + Scripts::MyScript.start(["zoo", "my_special_param", "--param=normal_param"]).should == "my_special_param" end it "does not set a value in the options hash" do - BrokenCounter.start(["1", "2", "--third", "3"])[0].must be_nil + BrokenCounter.start(["1", "2", "--third", "3"])[0].should be_nil end end describe "#arguments" do it "returns the arguments for the class" do - MyCounter.arguments.must have(2).items + MyCounter.arguments.should have(2).items end end describe "#class_option" do it "sets options class wise" do - MyCounter.start(["1", "2", "--third", "3"])[2].must == 3 + MyCounter.start(["1", "2", "--third", "3"])[2].should == 3 end it "does not create an accessor for it" do - BrokenCounter.start(["1", "2", "--third", "3"])[3].must be_false + BrokenCounter.start(["1", "2", "--third", "3"])[3].should be_false end end describe "#class_options" do it "sets default options overwriting superclass definitions" do options = Scripts::MyScript.class_options - options[:force].must_not be_required + options[:force].should_not be_required end end describe "#remove_argument" do it "removes previous defined arguments from class" do - ClearCounter.arguments.must be_empty + ClearCounter.arguments.should be_empty end it "undefine accessors if required" do - ClearCounter.new.must_not respond_to(:first) - ClearCounter.new.must_not respond_to(:second) + ClearCounter.new.should_not respond_to(:first) + ClearCounter.new.should_not respond_to(:second) end end describe "#remove_class_option" do it "removes previous defined class option" do - ClearCounter.class_options[:third].must be_nil + ClearCounter.class_options[:third].should be_nil end end @@ -109,73 +109,73 @@ def hello end it "shows options description" do - @content.must =~ /# The third argument/ + @content.should =~ /# The third argument/ end it "shows usage with banner content" do - @content.must =~ /\[\-\-third=THREE\]/ + @content.should =~ /\[\-\-third=THREE\]/ end it "shows default values below description" do - @content.must =~ /# Default: 3/ + @content.should =~ /# Default: 3/ end it "shows options in different groups" do - @content.must =~ /Options\:/ - @content.must =~ /Runtime options\:/ - @content.must =~ /\-p, \[\-\-pretend\]/ + @content.should =~ /Options\:/ + @content.should =~ /Runtime options\:/ + @content.should =~ /\-p, \[\-\-pretend\]/ end it "use padding in options that does not have aliases" do - @content.must =~ /^ -t, \[--third/ - @content.must =~ /^ \[--fourth/ + @content.should =~ /^ -t, \[--third/ + @content.should =~ /^ \[--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.must =~ /Foo options\:/ - content.must =~ /--last-name=LAST_NAME/ + content.should =~ /Foo options\:/ + content.should =~ /--last-name=LAST_NAME/ end end describe "#namespace" do it "returns the default class namespace" do - Scripts::MyScript.namespace.must == "scripts:my_script" + Scripts::MyScript.namespace.should == "scripts:my_script" end it "sets a namespace to the class" do - Scripts::MyDefaults.namespace.must == "default" + Scripts::MyDefaults.namespace.should == "default" end end describe "#group" do it "sets a group" do - MyScript.group.must == "script" + MyScript.group.should == "script" end it "inherits the group from parent" do - MyChildScript.group.must == "script" + MyChildScript.group.should == "script" end it "defaults to standard if no group is given" do - Amazing.group.must == "standard" + Amazing.group.should == "standard" end end describe "#subclasses" do it "tracks its subclasses in an Array" do - Thor::Base.subclasses.must include(MyScript) - Thor::Base.subclasses.must include(MyChildScript) - Thor::Base.subclasses.must include(Scripts::MyScript) + Thor::Base.subclasses.should include(MyScript) + Thor::Base.subclasses.should include(MyChildScript) + Thor::Base.subclasses.should 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)].must == [ + Thor::Base.subclass_files[File.expand_path(thorfile)].should == [ MyScript, MyScript::AnotherScript, MyChildScript, Barn, Scripts::MyScript, Scripts::MyDefaults, Scripts::ChildDefault ] @@ -183,46 +183,46 @@ def hello 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)].must include(Amazing) - Thor::Base.subclass_files[File.expand_path(__FILE__)].must include(Amazing) + Thor::Base.subclass_files[File.expand_path(thorfile)].should include(Amazing) + Thor::Base.subclass_files[File.expand_path(__FILE__)].should include(Amazing) end end describe "#tasks" do it "returns a list with all tasks defined in this class" do - MyChildScript.new.must respond_to("animal") - MyChildScript.tasks.keys.must include("animal") + MyChildScript.new.should respond_to("animal") + MyChildScript.tasks.keys.should include("animal") end it "raises an error if a task with reserved word is defined" do lambda { klass = Class.new(Thor::Group) klass.class_eval "def shell; end" - }.must raise_error(RuntimeError, /"shell" is a Thor reserved word and cannot be defined as task/) + }.should 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.must respond_to("foo") - MyChildScript.all_tasks.keys.must include("foo") + MyChildScript.new.should respond_to("foo") + MyChildScript.all_tasks.keys.should include("foo") end end describe "#remove_task" do it "removes the task from its tasks hash" do - MyChildScript.tasks.keys.must_not include("bar") - MyChildScript.tasks.keys.must_not include("boom") + MyChildScript.tasks.keys.should_not include("bar") + MyChildScript.tasks.keys.should_not include("boom") end it "undefines the method if desired" do - MyChildScript.new.must_not respond_to("boom") + MyChildScript.new.should_not 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.must == 13 + MyCounter.get_from_super.should == 13 end end @@ -230,40 +230,40 @@ def hello it "raises an error instead of rescueing if --debug is given" do lambda { MyScript.start ["what", "--debug"] - }.must raise_error(Thor::UndefinedTaskError, 'Could not find task "what" in "my_script" namespace.') + }.should raise_error(Thor::UndefinedTaskError, 'Could not find task "what" in "my_script" namespace.') end it "does not steal args" do args = ["foo", "bar", "--force", "true"] MyScript.start(args) - args.must == ["foo", "bar", "--force", "true"] + args.should == ["foo", "bar", "--force", "true"] end it "checks unknown options" do capture(:stderr) { MyScript.start(["foo", "bar", "--force", "true", "--unknown", "baz"]) - }.strip.must == "Unknown switches '--unknown'" + }.strip.should == "Unknown switches '--unknown'" end it "checks unknown options except specified" do capture(:stderr) { - MyScript.start(["with_optional", "NAME", "--omg", "--invalid"]).must == ["NAME", {}] - }.strip.must be_empty + MyScript.start(["with_optional", "NAME", "--omg", "--invalid"]).should == ["NAME", {}] + }.strip.should be_empty end end describe "attr_*" do it "should not add attr_reader as a task" do - capture(:stderr){ MyScript.start(["another_attribute"]) }.must =~ /Could not find/ + capture(:stderr){ MyScript.start(["another_attribute"]) }.should =~ /Could not find/ end it "should not add attr_writer as a task" do - capture(:stderr){ MyScript.start(["another_attribute=", "foo"]) }.must =~ /Could not find/ + capture(:stderr){ MyScript.start(["another_attribute=", "foo"]) }.should =~ /Could not find/ end it "should not add attr_accessor as a task" do - capture(:stderr){ MyScript.start(["some_attribute"]) }.must =~ /Could not find/ - capture(:stderr){ MyScript.start(["some_attribute=", "foo"]) }.must =~ /Could not find/ + capture(:stderr){ MyScript.start(["some_attribute"]) }.should =~ /Could not find/ + capture(:stderr){ MyScript.start(["some_attribute=", "foo"]) }.should =~ /Could not find/ end end end diff --git a/spec/core_ext/hash_with_indifferent_access_spec.rb b/spec/core_ext/hash_with_indifferent_access_spec.rb index 7eeb2b618..bbfa17591 100644 --- a/spec/core_ext/hash_with_indifferent_access_spec.rb +++ b/spec/core_ext/hash_with_indifferent_access_spec.rb @@ -7,37 +7,37 @@ end it "has values accessible by either strings or symbols" do - @hash['foo'].must == 'bar' - @hash[:foo].must == 'bar' + @hash['foo'].should == 'bar' + @hash[:foo].should == 'bar' - @hash.values_at(:foo, :baz).must == ['bar', 'bee'] - @hash.delete(:foo).must == 'bar' + @hash.values_at(:foo, :baz).should == ['bar', 'bee'] + @hash.delete(:foo).should == 'bar' end it "handles magic boolean predicates" do - @hash.force?.must be_true - @hash.foo?.must be_true - @hash.nothing?.must be_false + @hash.force?.should be_true + @hash.foo?.should be_true + @hash.nothing?.should be_false end it "handles magic comparisions" do - @hash.foo?('bar').must be_true - @hash.foo?('bee').must be_false + @hash.foo?('bar').should be_true + @hash.foo?('bee').should be_false end it "maps methods to keys" do - @hash.foo.must == @hash['foo'] + @hash.foo.should == @hash['foo'] end it "merges keys independent if they are symbols or strings" do @hash.merge!('force' => false, :baz => "boom") - @hash[:force].must == false - @hash[:baz].must == "boom" + @hash[:force].should == false + @hash[:baz].should == "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].must == false - other[:baz].must == "boom" + other[:force].should == false + other[:baz].should == "boom" end end diff --git a/spec/core_ext/ordered_hash_spec.rb b/spec/core_ext/ordered_hash_spec.rb index d8b530959..126ccf216 100644 --- a/spec/core_ext/ordered_hash_spec.rb +++ b/spec/core_ext/ordered_hash_spec.rb @@ -8,7 +8,7 @@ describe "without any items" do it "returns nil for an undefined key" do - @hash["foo"].must be_nil + @hash["foo"].should 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.must be_empty - @hash.values.must be_empty + @hash.keys.should be_empty + @hash.values.should be_empty end it "must be empty" do - @hash.must be_empty + @hash.should be_empty end end @@ -35,15 +35,15 @@ end it "returns nil for an undefined key" do - @hash[:boom].must be_nil + @hash[:boom].should be_nil end it "returns the value for each key" do - @hash[:foo].must == "Foo!" - @hash[:bar].must == "Bar!" - @hash[:baz].must == "Baz!" - @hash[:bop].must == "Bop!" - @hash[:bat].must == "Bat!" + @hash[:foo].should == "Foo!" + @hash[:bar].should == "Bar!" + @hash[:baz].should == "Baz!" + @hash[:bop].should == "Bop!" + @hash[:bat].should == "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.must == [[:foo, "Foo!"], [:bar, "Bar!"], [:baz, "Baz!"], + arr.should == [[:foo, "Foo!"], [:bar, "Bar!"], [:baz, "Baz!"], [:bop, "Bop!"], [:bat, "Bat!"]] end it "returns the keys in order of insertion" do - @hash.keys.must == [:foo, :bar, :baz, :bop, :bat] + @hash.keys.should == [:foo, :bar, :baz, :bop, :bat] end it "returns the values in order of insertion" do - @hash.values.must == ["Foo!", "Bar!", "Baz!", "Bop!", "Bat!"] + @hash.values.should == ["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.must == ["Foo!", "Bar!", "Bip!", "Bop!", "Bat!"] + @hash.values.should == ["Foo!", "Bar!", "Bip!", "Bop!", "Bat!"] @hash[:foo] = "Bip!" - @hash.values.must == ["Bip!", "Bar!", "Bip!", "Bop!", "Bat!"] + @hash.values.should == ["Bip!", "Bar!", "Bip!", "Bop!", "Bat!"] @hash[:bat] = "Bip!" - @hash.values.must == ["Bip!", "Bar!", "Bip!", "Bop!", "Bip!"] + @hash.values.should == ["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.must == ["Foo!", "Bar!", "Baz!", "Bop!", "Bat!", "one", "two", "three"] + @hash.merge(other_hash).values.should == ["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].must == "bar" - @hash[:bar].must == "Bar!" + @hash.merge(other_hash)[:bar].should == "bar" + @hash[:bar].should == "Bar!" end it "converts to an array" do - @hash.to_a.must == [[:foo, "Foo!"], [:bar, "Bar!"], [:baz, "Baz!"], [:bop, "Bop!"], [:bat, "Bat!"]] + @hash.to_a.should == [[:foo, "Foo!"], [:bar, "Bar!"], [:baz, "Baz!"], [:bop, "Bop!"], [:bat, "Bat!"]] end it "must not be empty" do - @hash.must_not be_empty + @hash.should_not be_empty end it "deletes values from hash" do - @hash.delete(:baz).must == "Baz!" - @hash.values.must == ["Foo!", "Bar!", "Bop!", "Bat!"] + @hash.delete(:baz).should == "Baz!" + @hash.values.should == ["Foo!", "Bar!", "Bop!", "Bat!"] - @hash.delete(:foo).must == "Foo!" - @hash.values.must == ["Bar!", "Bop!", "Bat!"] + @hash.delete(:foo).should == "Foo!" + @hash.values.should == ["Bar!", "Bop!", "Bat!"] - @hash.delete(:bat).must == "Bat!" - @hash.values.must == ["Bar!", "Bop!"] + @hash.delete(:bat).should == "Bat!" + @hash.values.should == ["Bar!", "Bop!"] end it "returns nil if the value to be deleted can't be found" do - @hash.delete(:nothing).must be_nil + @hash.delete(:nothing).should be_nil end end end diff --git a/spec/group_spec.rb b/spec/group_spec.rb index fa74355a9..c4e103610 100644 --- a/spec/group_spec.rb +++ b/spec/group_spec.rb @@ -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.must == ["bar", "foo", "baz"] - ChildGroup.new.baz("bar").must == "bar" + ChildGroup.start.should == ["bar", "foo", "baz"] + ChildGroup.new.baz("bar").should == "bar" end end describe "#start" do it "invokes all the tasks under the Thor group" do - MyCounter.start(["1", "2", "--third", "3"]).must == [ 1, 2, 3 ] + MyCounter.start(["1", "2", "--third", "3"]).should == [ 1, 2, 3 ] end it "uses argument default value" do - MyCounter.start(["1", "--third", "3"]).must == [ 1, 2, 3 ] + MyCounter.start(["1", "--third", "3"]).should == [ 1, 2, 3 ] end it "invokes all the tasks in the Thor group and his parents" do - BrokenCounter.start(["1", "2", "--third", "3"]).must == [ nil, 2, 3, false, 5 ] + BrokenCounter.start(["1", "2", "--third", "3"]).should == [ nil, 2, 3, false, 5 ] end it "raises an error if a required argument is added after a non-required" do lambda { MyCounter.argument(:foo, :type => :string) - }.must raise_error(ArgumentError, 'You cannot have "foo" as required argument after the non-required argument "second".') + }.should 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"]) }.must raise_error + lambda { BrokenCounter.start(["1", "2", "--fail"]) }.should raise_error end it "raises an error when a Thor group task expects arguments" do - lambda { WhinyGenerator.start }.must raise_error(ArgumentError, /Are you sure it has arity equals to 0\?/) + lambda { WhinyGenerator.start }.should raise_error(ArgumentError, /Are you sure it has arity equals to 0\?/) end it "invokes help message if any of the shortcuts is given" do @@ -43,15 +43,15 @@ describe "#desc" do it "sets the description for a given class" do - MyCounter.desc.must == "Description:\n This generator runs three tasks: one, two and three.\n" + MyCounter.desc.should == "Description:\n This generator runs three tasks: one, two and three.\n" end it "can be inherited" do - BrokenCounter.desc.must == "Description:\n This generator runs three tasks: one, two and three.\n" + BrokenCounter.desc.should == "Description:\n This generator runs three tasks: one, two and three.\n" end it "can be nil" do - WhinyGenerator.desc.must be_nil + WhinyGenerator.desc.should be_nil end end @@ -61,17 +61,17 @@ end it "provides usage information" do - @content.must =~ /my_counter N \[N\]/ + @content.should =~ /my_counter N \[N\]/ end it "shows description" do - @content.must =~ /Description:/ - @content.must =~ /This generator runs three tasks: one, two and three./ + @content.should =~ /Description:/ + @content.should =~ /This generator runs three tasks: one, two and three./ end it "shows options information" do - @content.must =~ /Options/ - @content.must =~ /\[\-\-third=THREE\]/ + @content.should =~ /Options/ + @content.should =~ /\[\-\-third=THREE\]/ end end @@ -81,28 +81,28 @@ end it "allows to invoke a class from the class binding" do - @content.must =~ /1\n2\n3\n4\n5\n/ + @content.should =~ /1\n2\n3\n4\n5\n/ end it "shows invocation information to the user" do - @content.must =~ /invoke Defined/ + @content.should =~ /invoke Defined/ end it "uses padding on status generated by the invoked class" do - @content.must =~ /finished counting/ + @content.should =~ /finished counting/ end it "allows invocation to be configured with blocks" do capture(:stdout) do - F.start.must == ["Valim, Jose"] + F.start.should == ["Valim, Jose"] end end it "shows invoked options on help" do content = capture(:stdout){ E.help(Thor::Base.shell.new) } - content.must =~ /Defined options:/ - content.must =~ /\[--unused\]/ - content.must =~ /# This option has no use/ + content.should =~ /Defined options:/ + content.should =~ /\[--unused\]/ + content.should =~ /# This option has no use/ end end @@ -113,36 +113,36 @@ end it "allows to invoke a class from the class binding by a default option" do - @content.must =~ /1\n2\n3\n4\n5\n/ + @content.should =~ /1\n2\n3\n4\n5\n/ end it "does not invoke if the option is nil" do - capture(:stdout){ G.start(["--skip-invoked"]) }.must_not =~ /invoke/ + capture(:stdout){ G.start(["--skip-invoked"]) }.should_not =~ /invoke/ end it "prints a message if invocation cannot be found" do content = capture(:stdout){ G.start(["--invoked", "unknown"]) } - content.must =~ /error unknown \[not found\]/ + content.should =~ /error unknown \[not found\]/ end it "allows to invoke a class from the class binding by the given option" do content = capture(:stdout){ G.start(["--invoked", "e"]) } - content.must =~ /invoke e/ + content.should =~ /invoke e/ end it "shows invocation information to the user" do - @content.must =~ /invoke defined/ + @content.should =~ /invoke defined/ end it "uses padding on status generated by the invoked class" do - @content.must =~ /finished counting/ + @content.should =~ /finished counting/ end it "shows invoked options on help" do content = capture(:stdout){ G.help(Thor::Base.shell.new) } - content.must =~ /defined options:/ - content.must =~ /\[--unused\]/ - content.must =~ /# This option has no use/ + content.should =~ /defined options:/ + content.should =~ /\[--unused\]/ + content.should =~ /# This option has no use/ end end @@ -152,26 +152,26 @@ end it "allows to invoke a class from the class binding by a default option" do - @content.must =~ /1\n2\n3\n4\n5\n/ + @content.should =~ /1\n2\n3\n4\n5\n/ end it "does not invoke if the option is false" do - capture(:stdout){ H.start(["--no-defined"]) }.must_not =~ /invoke/ + capture(:stdout){ H.start(["--no-defined"]) }.should_not =~ /invoke/ end it "shows invocation information to the user" do - @content.must =~ /invoke defined/ + @content.should =~ /invoke defined/ end it "uses padding on status generated by the invoked class" do - @content.must =~ /finished counting/ + @content.should =~ /finished counting/ end it "shows invoked options on help" do content = capture(:stdout){ H.help(Thor::Base.shell.new) } - content.must =~ /defined options:/ - content.must =~ /\[--unused\]/ - content.must =~ /# This option has no use/ + content.should =~ /defined options:/ + content.should =~ /\[--unused\]/ + content.should =~ /# This option has no use/ end end end diff --git a/spec/invocation_spec.rb b/spec/invocation_spec.rb index 943710f60..61113d9e5 100644 --- a/spec/invocation_spec.rb +++ b/spec/invocation_spec.rb @@ -4,82 +4,82 @@ describe Thor::Invocation do describe "#invoke" do it "invokes a task inside another task" do - capture(:stdout){ A.new.invoke(:two) }.must == "2\n3\n" + capture(:stdout){ A.new.invoke(:two) }.should == "2\n3\n" end it "invokes a task just once" do - capture(:stdout){ A.new.invoke(:one) }.must == "1\n2\n3\n" + capture(:stdout){ A.new.invoke(:one) }.should == "1\n2\n3\n" end it "invokes a task just once even if they belongs to different classes" do - capture(:stdout){ Defined.new.invoke(:one) }.must == "1\n2\n3\n4\n5\n" + capture(:stdout){ Defined.new.invoke(:one) }.should == "1\n2\n3\n4\n5\n" end it "invokes a task with arguments" do - A.new.invoke(:five, [5]).must be_true - A.new.invoke(:five, [7]).must be_false + A.new.invoke(:five, [5]).should be_true + A.new.invoke(:five, [7]).should be_false end it "invokes the default task if none is given to a Thor class" do content = capture(:stdout){ A.new.invoke("b") } - content.must =~ /Tasks/ - content.must =~ /LAST_NAME/ + content.should =~ /Tasks/ + content.should =~ /LAST_NAME/ end it "accepts a class as argument without a task to invoke" do content = capture(:stdout){ A.new.invoke(B) } - content.must =~ /Tasks/ - content.must =~ /LAST_NAME/ + content.should =~ /Tasks/ + content.should =~ /LAST_NAME/ end it "accepts a class as argument with a task to invoke" do base = A.new([], :last_name => "Valim") - base.invoke(B, :one, ["Jose"]).must == "Valim, Jose" + base.invoke(B, :one, ["Jose"]).should == "Valim, Jose" end it "allows customized options to be given" do base = A.new([], :last_name => "Wrong") - base.invoke(B, :one, ["Jose"], :last_name => "Valim").must == "Valim, Jose" + base.invoke(B, :one, ["Jose"], :last_name => "Valim").should == "Valim, Jose" end it "reparses options in the new class" do - A.start(["invoker", "--last-name", "Valim"]).must == "Valim, Jose" + A.start(["invoker", "--last-name", "Valim"]).should == "Valim, Jose" end it "shares initialize options with invoked class" do - A.new([], :foo => :bar).invoke("b:two").must == { "foo" => :bar } + A.new([], :foo => :bar).invoke("b:two").should == { "foo" => :bar } end it "dump configuration values to be used in the invoked class" do base = A.new - base.invoke("b:three").shell.must == base.shell + base.invoke("b:three").shell.should == base.shell end it "allow extra configuration values to be given" do base, shell = A.new, Thor::Base.shell.new - base.invoke("b:three", [], {}, :shell => shell).shell.must == shell + base.invoke("b:three", [], {}, :shell => shell).shell.should == shell end it "invokes a Thor::Group and all of its tasks" do - capture(:stdout){ A.new.invoke(:c) }.must == "1\n2\n3\n" + capture(:stdout){ A.new.invoke(:c) }.should == "1\n2\n3\n" end it "does not invoke a Thor::Group twice" do base = A.new silence(:stdout){ base.invoke(:c) } - capture(:stdout){ base.invoke(:c) }.must be_empty + capture(:stdout){ base.invoke(:c) }.should be_empty end it "does not invoke any of Thor::Group tasks twice" do base = A.new silence(:stdout){ base.invoke(:c) } - capture(:stdout){ base.invoke("c:one") }.must be_empty + capture(:stdout){ base.invoke("c:one") }.should be_empty end it "raises Thor::UndefinedTaskError if the task can't be found" do lambda do A.new.invoke("foo:bar") - end.must raise_error(Thor::UndefinedTaskError) + end.should raise_error(Thor::UndefinedTaskError) end it "raises Thor::UndefinedTaskError if the task can't be found even if all tasks where already executed" do @@ -88,13 +88,13 @@ lambda do base.invoke("foo:bar") - end.must raise_error(Thor::UndefinedTaskError) + end.should raise_error(Thor::UndefinedTaskError) end it "raises an error if a non Thor class is given" do lambda do A.new.invoke(Object) - end.must raise_error(RuntimeError, "Expected Thor class, got Object") + end.should raise_error(RuntimeError, "Expected Thor class, got Object") end end end diff --git a/spec/parser/argument_spec.rb b/spec/parser/argument_spec.rb index 3b735c554..848f6e88c 100644 --- a/spec/parser/argument_spec.rb +++ b/spec/parser/argument_spec.rb @@ -11,37 +11,37 @@ def argument(name, type=:string, default=nil, required=nil) it "raises an error if name is not supplied" do lambda { argument(nil) - }.must raise_error(ArgumentError, "Argument name can't be nil.") + }.should raise_error(ArgumentError, "Argument name can't be nil.") end it "raises an error if type is unknown" do lambda { argument(:task, :unknown) - }.must raise_error(ArgumentError, "Type :unknown is not valid for arguments.") + }.should raise_error(ArgumentError, "Type :unknown is not valid for arguments.") end it "raises an error if argument is required and have default values" do lambda { argument(:task, :string, "bar", true) - }.must raise_error(ArgumentError, "An argument cannot be required and have default value.") + }.should raise_error(ArgumentError, "An argument cannot be required and have default value.") end end describe "#usage" do it "returns usage for string types" do - argument(:foo, :string).usage.must == "FOO" + argument(:foo, :string).usage.should == "FOO" end it "returns usage for numeric types" do - argument(:foo, :numeric).usage.must == "N" + argument(:foo, :numeric).usage.should == "N" end it "returns usage for array types" do - argument(:foo, :array).usage.must == "one two three" + argument(:foo, :array).usage.should == "one two three" end it "returns usage for hash types" do - argument(:foo, :hash).usage.must == "key:value" + argument(:foo, :hash).usage.should == "key:value" end end end diff --git a/spec/parser/arguments_spec.rb b/spec/parser/arguments_spec.rb index ca7b3ed74..3f4073fe9 100644 --- a/spec/parser/arguments_spec.rb +++ b/spec/parser/arguments_spec.rb @@ -18,47 +18,47 @@ def parse(*args) describe "#parse" do it "parses arguments in the given order" do create :string => nil, :numeric => nil - parse("name", "13")["string"].must == "name" - parse("name", "13")["numeric"].must == 13 + parse("name", "13")["string"].should == "name" + parse("name", "13")["numeric"].should == 13 end it "accepts hashes" do create :string => nil, :hash => nil - parse("product", "title:string", "age:integer")["string"].must == "product" - parse("product", "title:string", "age:integer")["hash"].must == { "title" => "string", "age" => "integer"} + parse("product", "title:string", "age:integer")["string"].should == "product" + parse("product", "title:string", "age:integer")["hash"].should == { "title" => "string", "age" => "integer"} end it "accepts arrays" do create :string => nil, :array => nil - parse("product", "title", "age")["string"].must == "product" - parse("product", "title", "age")["array"].must == %w(title age) + parse("product", "title", "age")["string"].should == "product" + parse("product", "title", "age")["array"].should == %w(title age) end describe "with no inputs" do it "and no arguments returns an empty hash" do create - parse.must == {} + parse.should == {} end it "and required arguments raises an error" do create :string => nil, :numeric => nil - lambda { parse }.must raise_error(Thor::RequiredArgumentMissingError, "No value provided for required arguments 'string', 'numeric'") + lambda { parse }.should raise_error(Thor::RequiredArgumentMissingError, "No value provided for required arguments 'string', 'numeric'") end it "and default arguments returns default values" do create :string => "name", :numeric => 13 - parse.must == { "string" => "name", "numeric" => 13 } + parse.should == { "string" => "name", "numeric" => 13 } end end it "returns the input if it's already parsed" do create :string => nil, :hash => nil, :array => nil, :numeric => nil - parse("", 0, {}, []).must == { "string" => "", "numeric" => 0, "hash" => {}, "array" => [] } + parse("", 0, {}, []).should == { "string" => "", "numeric" => 0, "hash" => {}, "array" => [] } end it "returns the default value if none is provided" do create :string => "foo", :numeric => 3.0 - parse("bar").must == { "string" => "bar", "numeric" => 3.0 } + parse("bar").should == { "string" => "bar", "numeric" => 3.0 } end end end diff --git a/spec/parser/option_spec.rb b/spec/parser/option_spec.rb index ab03b0e9c..1c216c819 100644 --- a/spec/parser/option_spec.rb +++ b/spec/parser/option_spec.rb @@ -15,187 +15,187 @@ def option(name, *args) describe "with value as a symbol" do describe "and symbol is a valid type" do it "has type equals to the symbol" do - parse(:foo, :string).type.must == :string - parse(:foo, :numeric).type.must == :numeric + parse(:foo, :string).type.should == :string + parse(:foo, :numeric).type.should == :numeric end it "has not default value" do - parse(:foo, :string).default.must be_nil - parse(:foo, :numeric).default.must be_nil + parse(:foo, :string).default.should be_nil + parse(:foo, :numeric).default.should be_nil end end describe "equals to :required" do it "has type equals to :string" do - parse(:foo, :required).type.must == :string + parse(:foo, :required).type.should == :string end it "has no default value" do - parse(:foo, :required).default.must be_nil + parse(:foo, :required).default.should be_nil end end describe "and symbol is not a reserved key" do it "has type equals to :string" do - parse(:foo, :bar).type.must == :string + parse(:foo, :bar).type.should == :string end it "has no default value" do - parse(:foo, :bar).default.must be_nil + parse(:foo, :bar).default.should be_nil end end end describe "with value as hash" do it "has default type :hash" do - parse(:foo, :a => :b).type.must == :hash + parse(:foo, :a => :b).type.should == :hash end it "has default value equals to the hash" do - parse(:foo, :a => :b).default.must == { :a => :b } + parse(:foo, :a => :b).default.should == { :a => :b } end end describe "with value as array" do it "has default type :array" do - parse(:foo, [:a, :b]).type.must == :array + parse(:foo, [:a, :b]).type.should == :array end it "has default value equals to the array" do - parse(:foo, [:a, :b]).default.must == [:a, :b] + parse(:foo, [:a, :b]).default.should == [:a, :b] end end describe "with value as string" do it "has default type :string" do - parse(:foo, "bar").type.must == :string + parse(:foo, "bar").type.should == :string end it "has default value equals to the string" do - parse(:foo, "bar").default.must == "bar" + parse(:foo, "bar").default.should == "bar" end end describe "with value as numeric" do it "has default type :numeric" do - parse(:foo, 2.0).type.must == :numeric + parse(:foo, 2.0).type.should == :numeric end it "has default value equals to the numeric" do - parse(:foo, 2.0).default.must == 2.0 + parse(:foo, 2.0).default.should == 2.0 end end describe "with value as boolean" do it "has default type :boolean" do - parse(:foo, true).type.must == :boolean - parse(:foo, false).type.must == :boolean + parse(:foo, true).type.should == :boolean + parse(:foo, false).type.should == :boolean end it "has default value equals to the boolean" do - parse(:foo, true).default.must == true - parse(:foo, false).default.must == false + parse(:foo, true).default.should == true + parse(:foo, false).default.should == false end end describe "with key as a symbol" do it "sets the name equals to the key" do - parse(:foo, true).name.must == "foo" + parse(:foo, true).name.should == "foo" end end describe "with key as an array" do it "sets the first items in the array to the name" do - parse([:foo, :bar, :baz], true).name.must == "foo" + parse([:foo, :bar, :baz], true).name.should == "foo" end it "sets all other items as aliases" do - parse([:foo, :bar, :baz], true).aliases.must == [:bar, :baz] + parse([:foo, :bar, :baz], true).aliases.should == [:bar, :baz] end end end it "returns the switch name" do - option("foo").switch_name.must == "--foo" - option("--foo").switch_name.must == "--foo" + option("foo").switch_name.should == "--foo" + option("--foo").switch_name.should == "--foo" end it "returns the human name" do - option("foo").human_name.must == "foo" - option("--foo").human_name.must == "foo" + option("foo").human_name.should == "foo" + option("--foo").human_name.should == "foo" end it "converts underscores to dashes" do - option("foo_bar").switch_name.must == "--foo-bar" + option("foo_bar").switch_name.should == "--foo-bar" end it "can be required and have default values" do option = option("foo", nil, true, :string, "bar") - option.default.must == "bar" - option.must be_required + option.default.should == "bar" + option.should be_required end it "cannot be required and have type boolean" do lambda { option("foo", nil, true, :boolean) - }.must raise_error(ArgumentError, "An option cannot be boolean and required.") + }.should raise_error(ArgumentError, "An option cannot be boolean and required.") end it "allows type predicates" do - parse(:foo, :string).must be_string - parse(:foo, :boolean).must be_boolean - parse(:foo, :numeric).must be_numeric + parse(:foo, :string).should be_string + parse(:foo, :boolean).should be_boolean + parse(:foo, :numeric).should be_numeric end it "raises an error on method missing" do lambda { parse(:foo, :string).unknown? - }.must raise_error(NoMethodError) + }.should raise_error(NoMethodError) end describe "#usage" do it "returns usage for string types" do - parse(:foo, :string).usage.must == "[--foo=FOO]" + parse(:foo, :string).usage.should == "[--foo=FOO]" end it "returns usage for numeric types" do - parse(:foo, :numeric).usage.must == "[--foo=N]" + parse(:foo, :numeric).usage.should == "[--foo=N]" end it "returns usage for array types" do - parse(:foo, :array).usage.must == "[--foo=one two three]" + parse(:foo, :array).usage.should == "[--foo=one two three]" end it "returns usage for hash types" do - parse(:foo, :hash).usage.must == "[--foo=key:value]" + parse(:foo, :hash).usage.should == "[--foo=key:value]" end it "returns usage for boolean types" do - parse(:foo, :boolean).usage.must == "[--foo]" + parse(:foo, :boolean).usage.should == "[--foo]" end it "uses padding when no aliases is given" do - parse(:foo, :boolean).usage(4).must == " [--foo]" + parse(:foo, :boolean).usage(4).should == " [--foo]" end it "uses banner when supplied" do - option(:foo, nil, false, :string, nil, "BAR").usage.must == "[--foo=BAR]" + option(:foo, nil, false, :string, nil, "BAR").usage.should == "[--foo=BAR]" end it "checkes when banner is an empty string" do - option(:foo, nil, false, :string, nil, "").usage.must == "[--foo]" + option(:foo, nil, false, :string, nil, "").usage.should == "[--foo]" end describe "with required values" do it "does not show the usage between brackets" do - parse(:foo, :required).usage.must == "--foo=FOO" + parse(:foo, :required).usage.should == "--foo=FOO" end end describe "with aliases" do it "does not show the usage between brackets" do - parse([:foo, "-f", "-b"], :required).usage.must == "-f, -b, --foo=FOO" + parse([:foo, "-f", "-b"], :required).usage.should == "-f, -b, --foo=FOO" end end end diff --git a/spec/parser/options_spec.rb b/spec/parser/options_spec.rb index df2d5f148..e9652b04c 100644 --- a/spec/parser/options_spec.rb +++ b/spec/parser/options_spec.rb @@ -20,36 +20,36 @@ def check_unknown! describe "#to_switches" do it "turns true values into a flag" do - Thor::Options.to_switches(:color => true).must == "--color" + Thor::Options.to_switches(:color => true).should == "--color" end it "ignores nil" do - Thor::Options.to_switches(:color => nil).must == "" + Thor::Options.to_switches(:color => nil).should == "" end it "ignores false" do - Thor::Options.to_switches(:color => false).must == "" + Thor::Options.to_switches(:color => false).should == "" end it "writes --name value for anything else" do - Thor::Options.to_switches(:format => "specdoc").must == '--format "specdoc"' + Thor::Options.to_switches(:format => "specdoc").should == '--format "specdoc"' end it "joins several values" do switches = Thor::Options.to_switches(:color => true, :foo => "bar").split(' ').sort - switches.must == ['"bar"', "--color", "--foo"] + switches.should == ['"bar"', "--color", "--foo"] end it "accepts arrays" do - Thor::Options.to_switches(:count => [1,2,3]).must == "--count 1 2 3" + Thor::Options.to_switches(:count => [1,2,3]).should == "--count 1 2 3" end it "accepts hashes" do - Thor::Options.to_switches(:count => {:a => :b}).must == "--count a:b" + Thor::Options.to_switches(:count => {:a => :b}).should == "--count a:b" end it "accepts underscored options" do - Thor::Options.to_switches(:under_score_option => "foo bar").must == '--under_score_option "foo bar"' + Thor::Options.to_switches(:under_score_option => "foo bar").should == '--under_score_option "foo bar"' end end @@ -57,96 +57,96 @@ def check_unknown! describe "#parse" do it "allows multiple aliases for a given switch" do create ["--foo", "--bar", "--baz"] => :string - parse("--foo", "12")["foo"].must == "12" - parse("--bar", "12")["foo"].must == "12" - parse("--baz", "12")["foo"].must == "12" + parse("--foo", "12")["foo"].should == "12" + parse("--bar", "12")["foo"].should == "12" + parse("--baz", "12")["foo"].should == "12" end it "allows custom short names" do create "-f" => :string - parse("-f", "12").must == {"f" => "12"} + parse("-f", "12").should == {"f" => "12"} end it "allows custom short-name aliases" do create ["--bar", "-f"] => :string - parse("-f", "12").must == {"bar" => "12"} + parse("-f", "12").should == {"bar" => "12"} end it "accepts conjoined short switches" do create ["--foo", "-f"] => true, ["--bar", "-b"] => true, ["--app", "-a"] => true opts = parse("-fba") - opts["foo"].must be_true - opts["bar"].must be_true - opts["app"].must be_true + opts["foo"].should be_true + opts["bar"].should be_true + opts["app"].should be_true end it "accepts conjoined short switches with input" do create ["--foo", "-f"] => true, ["--bar", "-b"] => true, ["--app", "-a"] => :required opts = parse "-fba", "12" - opts["foo"].must be_true - opts["bar"].must be_true - opts["app"].must == "12" + opts["foo"].should be_true + opts["bar"].should be_true + opts["app"].should == "12" end it "returns the default value if none is provided" do create :foo => "baz", :bar => :required - parse("--bar", "boom")["foo"].must == "baz" + parse("--bar", "boom")["foo"].should == "baz" end it "returns the default value from defaults hash to required arguments" do create Hash[:bar => :required], Hash[:bar => "baz"] - parse["bar"].must == "baz" + parse["bar"].should == "baz" end it "gives higher priority to defaults given in the hash" do create Hash[:bar => true], Hash[:bar => false] - parse["bar"].must == false + parse["bar"].should == false end it "raises an error for unknown switches" do create :foo => "baz", :bar => :required parse("--bar", "baz", "--baz", "unknown") - lambda { check_unknown! }.must raise_error(Thor::UnknownArgumentError, "Unknown switches '--baz'") + lambda { check_unknown! }.should raise_error(Thor::UnknownArgumentError, "Unknown switches '--baz'") end it "skips leading non-switches" do create(:foo => "baz") - parse("asdf", "--foo", "bar").must == {"foo" => "bar"} + parse("asdf", "--foo", "bar").should == {"foo" => "bar"} end it "correctly recognizes things that look kind of like options, but aren't, as not options" do create(:foo => "baz") - parse("--asdf---asdf", "baz", "--foo", "--asdf---dsf--asdf").must == {"foo" => "--asdf---dsf--asdf"} + parse("--asdf---asdf", "baz", "--foo", "--asdf---dsf--asdf").should == {"foo" => "--asdf---dsf--asdf"} check_unknown! end it "excepts underscores in commandline args hash for boolean" do create :foo_bar => :boolean - parse("--foo_bar")["foo_bar"].must == true - parse("--no_foo_bar")["foo_bar"].must == false + parse("--foo_bar")["foo_bar"].should == true + parse("--no_foo_bar")["foo_bar"].should == false end it "excepts underscores in commandline args hash for strings" do create :foo_bar => :string, :baz_foo => :string - parse("--foo_bar", "baz")["foo_bar"].must == "baz" - parse("--baz_foo", "foo bar")["baz_foo"].must == "foo bar" + parse("--foo_bar", "baz")["foo_bar"].should == "baz" + parse("--baz_foo", "foo bar")["baz_foo"].should == "foo bar" end describe "with no input" do it "and no switches returns an empty hash" do create({}) - parse.must == {} + parse.should == {} end it "and several switches returns an empty hash" do create "--foo" => :boolean, "--bar" => :string - parse.must == {} + parse.should == {} end it "and a required switch raises an error" do create "--foo" => :required - lambda { parse }.must raise_error(Thor::RequiredArgumentMissingError, "No value provided for required options '--foo'") + lambda { parse }.should raise_error(Thor::RequiredArgumentMissingError, "No value provided for required options '--foo'") end end @@ -156,20 +156,20 @@ def check_unknown! end it "raises an error if the required switch has no argument" do - lambda { parse("--foo") }.must raise_error(Thor::MalformattedArgumentError) + lambda { parse("--foo") }.should raise_error(Thor::MalformattedArgumentError) end it "raises an error if the required switch isn't given" do - lambda { parse("--bar") }.must raise_error(Thor::RequiredArgumentMissingError) + lambda { parse("--bar") }.should raise_error(Thor::RequiredArgumentMissingError) end it "raises an error if the required switch is set to nil" do - lambda { parse("--no-foo") }.must raise_error(Thor::RequiredArgumentMissingError) + lambda { parse("--no-foo") }.should raise_error(Thor::RequiredArgumentMissingError) end it "does not raises an error if the required option has a default value" do create :foo => Thor::Option.new("foo", nil, true, :string, "baz"), :bar => :boolean - lambda { parse("--bar") }.must_not raise_error + lambda { parse("--bar") }.should_not raise_error end end @@ -179,43 +179,43 @@ def check_unknown! end it "accepts a switch assignment" do - parse("--foo", "12")["foo"].must == "12" + parse("--foo", "12")["foo"].should == "12" end it "accepts a switch= assignment" do - parse("-f=12")["foo"].must == "12" - parse("--foo=12")["foo"].must == "12" - parse("--foo=bar=baz")["foo"].must == "bar=baz" + parse("-f=12")["foo"].should == "12" + parse("--foo=12")["foo"].should == "12" + parse("--foo=bar=baz")["foo"].should == "bar=baz" end it "must accept underscores switch=value assignment" do create :foo_bar => :required - parse("--foo_bar=http://example.com/under_score/")["foo_bar"].must == "http://example.com/under_score/" + parse("--foo_bar=http://example.com/under_score/")["foo_bar"].should == "http://example.com/under_score/" end it "accepts a --no-switch format" do create "--foo" => "bar" - parse("--no-foo")["foo"].must be_nil + parse("--no-foo")["foo"].should be_nil end it "does not consume an argument for --no-switch format" do create "--cheese" => :string - parse('burger', '--no-cheese', 'fries')["cheese"].must be_nil + parse('burger', '--no-cheese', 'fries')["cheese"].should be_nil end it "accepts a --switch format on non required types" do create "--foo" => :string - parse("--foo")["foo"].must == "foo" + parse("--foo")["foo"].should == "foo" end it "accepts a --switch format on non required types with default values" do create "--baz" => :string, "--foo" => "bar" - parse("--baz", "bang", "--foo")["foo"].must == "bar" + parse("--baz", "bang", "--foo")["foo"].should == "bar" end it "overwrites earlier values with later values" do - parse("--foo=bar", "--foo", "12")["foo"].must == "12" - parse("--foo", "12", "--foo", "13")["foo"].must == "13" + parse("--foo=bar", "--foo", "12")["foo"].should == "12" + parse("--foo", "12", "--foo", "13")["foo"].should == "13" end end @@ -225,38 +225,38 @@ def check_unknown! end it "accepts --opt assignment" do - parse("--foo")["foo"].must == true - parse("--foo", "--bar")["foo"].must == true + parse("--foo")["foo"].should == true + parse("--foo", "--bar")["foo"].should == true end it "accepts --opt=value assignment" do - parse("--foo=true")["foo"].must == true - parse("--foo=false")["foo"].must == false + parse("--foo=true")["foo"].should == true + parse("--foo=false")["foo"].should == false end it "accepts --[no-]opt variant, setting false for value" do - parse("--no-foo")["foo"].must == false + parse("--no-foo")["foo"].should == false end it "accepts --[skip-]opt variant, setting false for value" do - parse("--skip-foo")["foo"].must == false + parse("--skip-foo")["foo"].should == false end it "will prefer 'no-opt' variant over inverting 'opt' if explicitly set" do create "--no-foo" => true - parse("--no-foo")["no-foo"].must == true + parse("--no-foo")["no-foo"].should == true end it "will prefer 'skip-opt' variant over inverting 'opt' if explicitly set" do create "--skip-foo" => true - parse("--skip-foo")["skip-foo"].must == true + parse("--skip-foo")["skip-foo"].should == true end it "accepts inputs in the human name format" do create :foo_bar => :boolean - parse("--foo-bar")["foo_bar"].must == true - parse("--no-foo-bar")["foo_bar"].must == false - parse("--skip-foo-bar")["foo_bar"].must == false + parse("--foo-bar")["foo_bar"].should == true + parse("--no-foo-bar")["foo_bar"].should == false + parse("--skip-foo-bar")["foo_bar"].should == false end end @@ -266,15 +266,15 @@ def check_unknown! end it "accepts a switch= assignment" do - parse("--attributes=name:string", "age:integer")["attributes"].must == {"name" => "string", "age" => "integer"} + parse("--attributes=name:string", "age:integer")["attributes"].should == {"name" => "string", "age" => "integer"} end it "accepts a switch assignment" do - parse("--attributes", "name:string", "age:integer")["attributes"].must == {"name" => "string", "age" => "integer"} + parse("--attributes", "name:string", "age:integer")["attributes"].should == {"name" => "string", "age" => "integer"} end it "must not mix values with other switches" do - parse("--attributes", "name:string", "age:integer", "--baz", "cool")["attributes"].must == {"name" => "string", "age" => "integer"} + parse("--attributes", "name:string", "age:integer", "--baz", "cool")["attributes"].should == {"name" => "string", "age" => "integer"} end end @@ -284,15 +284,15 @@ def check_unknown! end it "accepts a switch= assignment" do - parse("--attributes=a", "b", "c")["attributes"].must == ["a", "b", "c"] + parse("--attributes=a", "b", "c")["attributes"].should == ["a", "b", "c"] end it "accepts a switch assignment" do - parse("--attributes", "a", "b", "c")["attributes"].must == ["a", "b", "c"] + parse("--attributes", "a", "b", "c")["attributes"].should == ["a", "b", "c"] end it "must not mix values with other switches" do - parse("--attributes", "a", "b", "c", "--baz", "cool")["attributes"].must == ["a", "b", "c"] + parse("--attributes", "a", "b", "c", "--baz", "cool")["attributes"].should == ["a", "b", "c"] end end @@ -302,15 +302,15 @@ def check_unknown! end it "accepts a -nXY assignment" do - parse("-n12")["n"].must == 12 + parse("-n12")["n"].should == 12 end it "converts values to numeric types" do - parse("-n", "3", "-m", ".5").must == {"n" => 3, "m" => 0.5} + parse("-n", "3", "-m", ".5").should == {"n" => 3, "m" => 0.5} end it "raises error when value isn't numeric" do - lambda { parse("-n", "foo") }.must raise_error(Thor::MalformattedArgumentError, + lambda { parse("-n", "foo") }.should raise_error(Thor::MalformattedArgumentError, "Expected numeric value for '-n'; got \"foo\"") end end diff --git a/spec/rake_compat_spec.rb b/spec/rake_compat_spec.rb index 3f7cd9e12..f8d694cf5 100644 --- a/spec/rake_compat_spec.rb +++ b/spec/rake_compat_spec.rb @@ -28,41 +28,41 @@ class ThorTask < Thor describe Thor::RakeCompat do it "sets the rakefile application" do - ["rake_compat_spec.rb", "Thorfile"].must include(Rake.application.rakefile) + ["rake_compat_spec.rb", "Thorfile"].should include(Rake.application.rakefile) end it "adds rake tasks to thor classes too" do task = ThorTask.tasks["cool"] - task.must be + task.should be end it "uses rake tasks descriptions on thor" do - ThorTask.tasks["cool"].description.must == "Say it's cool" + ThorTask.tasks["cool"].description.should == "Say it's cool" end it "gets usage from rake tasks name" do - ThorTask.tasks["cool"].usage.must == "cool" + ThorTask.tasks["cool"].usage.should == "cool" end it "uses non namespaced name as description if non is available" do - ThorTask::HiperMega.tasks["super"].description.must == "super" + ThorTask::HiperMega.tasks["super"].description.should == "super" end it "converts namespaces to classes" do - ThorTask.const_get(:HiperMega).must == ThorTask::HiperMega + ThorTask.const_get(:HiperMega).should == ThorTask::HiperMega end it "does not add tasks from higher namespaces in lowers namespaces" do - ThorTask.tasks["super"].must_not be + ThorTask.tasks["super"].should_not be end it "invoking the thor task invokes the rake task" do capture(:stdout) do ThorTask.start ["cool"] - end.must == "COOL\n" + end.should == "COOL\n" capture(:stdout) do ThorTask::HiperMega.start ["super"] - end.must == "HIPER MEGA SUPER\n" + end.should == "HIPER MEGA SUPER\n" end end diff --git a/spec/register_spec.rb b/spec/register_spec.rb index a9c3226d2..5a1ab1973 100644 --- a/spec/register_spec.rb +++ b/spec/register_spec.rb @@ -63,23 +63,23 @@ def part_two describe ".register-ing a Thor subclass" do it "registers the plugin as a subcommand" do fireworks_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[exciting fireworks]) } - fireworks_output.must == "kaboom!\n" + fireworks_output.should == "kaboom!\n" end it "includes the plugin's usage in the help" do help_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[help]) } - help_output.must include('do exciting things') + help_output.should include('do exciting things') end context "when hidden" do it "omits the hidden plugin's usage from the help" do help_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[help]) } - help_output.must_not include('secret stuff') + help_output.should_not include('secret stuff') end it "registers the plugin as a subcommand" do secret_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[secret squirrel]) } - secret_output.must == "I love nuts\n" + secret_output.should == "I love nuts\n" end end end @@ -87,6 +87,6 @@ def part_two describe ".register-ing a Thor::Group subclass" do it "registers the group as a single command" do group_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[groupwork]) } - group_output.must == "part one\npart two\n" + group_output.should == "part one\npart two\n" end end diff --git a/spec/runner_spec.rb b/spec/runner_spec.rb index a81e98d41..48e39a736 100644 --- a/spec/runner_spec.rb +++ b/spec/runner_spec.rb @@ -4,88 +4,88 @@ describe Thor::Runner do describe "#help" do it "shows information about Thor::Runner itself" do - capture(:stdout){ Thor::Runner.start(["help"]) }.must =~ /List the available thor tasks/ + capture(:stdout){ Thor::Runner.start(["help"]) }.should =~ /List the available thor tasks/ end it "shows information about an specific Thor::Runner task" do content = capture(:stdout){ Thor::Runner.start(["help", "list"]) } - content.must =~ /List the available thor tasks/ - content.must_not =~ /help \[TASK\]/ + content.should =~ /List the available thor tasks/ + content.should_not =~ /help \[TASK\]/ end it "shows information about a specific Thor class" do content = capture(:stdout){ Thor::Runner.start(["help", "my_script"]) } - content.must =~ /zoo\s+# zoo around/m + content.should =~ /zoo\s+# zoo around/m end it "shows information about an specific task from an specific Thor class" do content = capture(:stdout){ Thor::Runner.start(["help", "my_script:zoo"]) } - content.must =~ /zoo around/ - content.must_not =~ /help \[TASK\]/ + content.should =~ /zoo around/ + content.should_not =~ /help \[TASK\]/ end it "shows information about a specific Thor group class" do content = capture(:stdout){ Thor::Runner.start(["help", "my_counter"]) } - content.must =~ /my_counter N/ + content.should =~ /my_counter N/ end it "raises error if a class/task cannot be found" do content = capture(:stderr){ Thor::Runner.start(["help", "unknown"]) } - content.strip.must == 'Could not find task "unknown" in "default" namespace.' + content.strip.should == 'Could not find task "unknown" in "default" namespace.' end end describe "#start" do it "invokes a task from Thor::Runner" do ARGV.replace ["list"] - capture(:stdout){ Thor::Runner.start }.must =~ /my_counter N/ + capture(:stdout){ Thor::Runner.start }.should =~ /my_counter N/ end it "invokes a task from a specific Thor class" do ARGV.replace ["my_script:zoo"] - Thor::Runner.start.must be_true + Thor::Runner.start.should be_true end it "invokes the default task from a specific Thor class if none is specified" do ARGV.replace ["my_script"] - Thor::Runner.start.must == "default task" + Thor::Runner.start.should == "default task" end it "forwads arguments to the invoked task" do ARGV.replace ["my_script:animal", "horse"] - Thor::Runner.start.must == ["horse"] + Thor::Runner.start.should == ["horse"] end it "invokes tasks through shortcuts" do ARGV.replace ["my_script", "-T", "horse"] - Thor::Runner.start.must == ["horse"] + Thor::Runner.start.should == ["horse"] end it "invokes a Thor::Group" do ARGV.replace ["my_counter", "1", "2", "--third", "3"] - Thor::Runner.start.must == [1, 2, 3] + Thor::Runner.start.should == [1, 2, 3] end it "raises an error if class/task can't be found" do ARGV.replace ["unknown"] content = capture(:stderr){ Thor::Runner.start } - content.strip.must == 'Could not find task "unknown" in "default" namespace.' + content.strip.should == 'Could not find task "unknown" in "default" namespace.' end it "does not swallow NoMethodErrors that occur inside the called method" do ARGV.replace ["my_script:call_unexistent_method"] - lambda { Thor::Runner.start }.must raise_error(NoMethodError) + lambda { Thor::Runner.start }.should raise_error(NoMethodError) end it "does not swallow Thor::Group InvocationError" do ARGV.replace ["whiny_generator"] - lambda { Thor::Runner.start }.must raise_error(ArgumentError, /Are you sure it has arity equals to 0\?/) + lambda { Thor::Runner.start }.should raise_error(ArgumentError, /Are you sure it has arity equals to 0\?/) end it "does not swallow Thor InvocationError" do ARGV.replace ["my_script:animal"] content = capture(:stderr) { Thor::Runner.start } - content.strip.must == '"animal" was called incorrectly. Call as "thor my_script:animal TYPE".' + content.strip.should == '"animal" was called incorrectly. Call as "thor my_script:animal TYPE".' end end @@ -112,53 +112,53 @@ it "gives a list of the available tasks" do ARGV.replace ["list"] content = capture(:stdout) { Thor::Runner.start } - content.must =~ /amazing:describe NAME\s+# say that someone is amazing/m + content.should =~ /amazing:describe NAME\s+# say that someone is amazing/m end it "gives a list of the available Thor::Group classes" do ARGV.replace ["list"] - capture(:stdout) { Thor::Runner.start }.must =~ /my_counter N/ + capture(:stdout) { Thor::Runner.start }.should =~ /my_counter N/ end it "can filter a list of the available tasks by --group" do ARGV.replace ["list", "--group", "standard"] - capture(:stdout) { Thor::Runner.start }.must =~ /amazing:describe NAME/ + capture(:stdout) { Thor::Runner.start }.should =~ /amazing:describe NAME/ ARGV.replace [] - capture(:stdout) { Thor::Runner.start }.must_not =~ /my_script:animal TYPE/ + capture(:stdout) { Thor::Runner.start }.should_not =~ /my_script:animal TYPE/ ARGV.replace ["list", "--group", "script"] - capture(:stdout) { Thor::Runner.start }.must =~ /my_script:animal TYPE/ + capture(:stdout) { Thor::Runner.start }.should =~ /my_script:animal TYPE/ end it "can skip all filters to show all tasks using --all" do ARGV.replace ["list", "--all"] content = capture(:stdout) { Thor::Runner.start } - content.must =~ /amazing:describe NAME/ - content.must =~ /my_script:animal TYPE/ + content.should =~ /amazing:describe NAME/ + content.should =~ /my_script:animal TYPE/ end it "doesn't list superclass tasks in the subclass" do ARGV.replace ["list"] - capture(:stdout) { Thor::Runner.start }.must_not =~ /amazing:help/ + capture(:stdout) { Thor::Runner.start }.should_not =~ /amazing:help/ end it "presents tasks in the default namespace with an empty namespace" do ARGV.replace ["list"] - capture(:stdout) { Thor::Runner.start }.must =~ /^thor :cow\s+# prints 'moo'/m + capture(:stdout) { Thor::Runner.start }.should =~ /^thor :cow\s+# prints 'moo'/m end it "runs tasks with an empty namespace from the default namespace" do ARGV.replace [":task_conflict"] - capture(:stdout) { Thor::Runner.start }.must == "task\n" + capture(:stdout) { Thor::Runner.start }.should == "task\n" end it "runs groups even when there is a task with the same name" do ARGV.replace ["task_conflict"] - capture(:stdout) { Thor::Runner.start }.must == "group\n" + capture(:stdout) { Thor::Runner.start }.should == "group\n" end it "runs tasks with no colon in the default namespace" do ARGV.replace ["cow"] - capture(:stdout) { Thor::Runner.start }.must == "moo\n" + capture(:stdout) { Thor::Runner.start }.should == "moo\n" end end @@ -180,8 +180,8 @@ it "displays the modules installed in a pretty way" do stdout = capture(:stdout) { Thor::Runner.start(["installed"]) } - stdout.must =~ /random\s*amazing/ - stdout.must =~ /amazing:describe NAME\s+# say that someone is amazing/m + stdout.should =~ /random\s*amazing/ + stdout.should =~ /amazing:describe NAME\s+# say that someone is amazing/m end end diff --git a/spec/shell/basic_spec.rb b/spec/shell/basic_spec.rb index ac7bd0376..7f5507349 100644 --- a/spec/shell/basic_spec.rb +++ b/spec/shell/basic_spec.rb @@ -8,10 +8,10 @@ def shell describe "#padding" do it "cannot be set to below zero" do shell.padding = 10 - shell.padding.must == 10 + shell.padding.should == 10 shell.padding = -1 - shell.padding.must == 0 + shell.padding.should == 0 end end @@ -19,7 +19,7 @@ def shell it "prints a message to the user and gets the response" do $stdout.should_receive(:print).with("Should I overwrite it? ") $stdin.should_receive(:gets).and_return('Sure') - shell.ask("Should I overwrite it?").must == "Sure" + shell.ask("Should I overwrite it?").should == "Sure" end end @@ -27,11 +27,11 @@ def shell it "asks the user and returns true if the user replies yes" do $stdout.should_receive(:print).with("Should I overwrite it? ") $stdin.should_receive(:gets).and_return('y') - shell.yes?("Should I overwrite it?").must === true + shell.yes?("Should I overwrite it?").should === true $stdout.should_receive(:print).with("Should I overwrite it? ") $stdin.should_receive(:gets).and_return('n') - shell.yes?("Should I overwrite it?").must_not === true + shell.yes?("Should I overwrite it?").should_not === true end end @@ -39,11 +39,11 @@ def shell it "asks the user and returns true if the user replies no" do $stdout.should_receive(:print).with("Should I overwrite it? ") $stdin.should_receive(:gets).and_return('n') - shell.no?("Should I overwrite it?").must === true + shell.no?("Should I overwrite it?").should === true $stdout.should_receive(:print).with("Should I overwrite it? ") $stdin.should_receive(:gets).and_return('Yes') - shell.no?("Should I overwrite it?").must === false + shell.no?("Should I overwrite it?").should === false end end @@ -115,7 +115,7 @@ def shell it "prints a table" do content = capture(:stdout){ shell.print_table(@table) } - content.must == <<-TABLE + content.should == <<-TABLE abc #123 first three #0 empty xyz #786 last three @@ -124,7 +124,7 @@ def shell it "prints a table with identation" do content = capture(:stdout){ shell.print_table(@table, :ident => 2) } - content.must == <<-TABLE + content.should == <<-TABLE abc #123 first three #0 empty xyz #786 last three @@ -134,7 +134,7 @@ def shell it "uses maximum terminal width" do shell.should_receive(:terminal_width).and_return(20) content = capture(:stdout){ shell.print_table(@table, :ident => 2, :truncate => true) } - content.must == <<-TABLE + content.should == <<-TABLE abc #123 firs... #0 empty xyz #786 last... @@ -143,7 +143,7 @@ def shell it "honors the colwidth option" do content = capture(:stdout){ shell.print_table(@table, :colwidth => 10)} - content.must == <<-TABLE + content.should == <<-TABLE abc #123 first three #0 empty xyz #786 last three @@ -161,19 +161,19 @@ def shell it "returns true if the user choose default option" do $stdout.stub!(:print) $stdin.should_receive(:gets).and_return('') - shell.file_collision('foo').must be_true + shell.file_collision('foo').should be_true end it "returns false if the user choose no" do $stdout.stub!(:print) $stdin.should_receive(:gets).and_return('n') - shell.file_collision('foo').must be_false + shell.file_collision('foo').should be_false end it "returns true if the user choose yes" do $stdout.stub!(:print) $stdin.should_receive(:gets).and_return('y') - shell.file_collision('foo').must be_true + shell.file_collision('foo').should be_true end it "shows help usage if the user choose help" do @@ -181,7 +181,7 @@ def shell $stdin.should_receive(:gets).and_return('h') $stdin.should_receive(:gets).and_return('n') help = capture(:stdout){ shell.file_collision('foo') } - help.must =~ /h \- help, show this help/ + help.should =~ /h \- help, show this help/ end it "quits if the user choose quit" do @@ -191,17 +191,17 @@ def shell lambda { shell.file_collision('foo') - }.must raise_error(SystemExit) + }.should raise_error(SystemExit) end it "always returns true if the user choose always" do $stdout.should_receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqh] ') $stdin.should_receive(:gets).and_return('a') - shell.file_collision('foo').must be_true + shell.file_collision('foo').should be_true $stdout.should_not_receive(:print) - shell.file_collision('foo').must be_true + shell.file_collision('foo').should be_true end describe "when a block is given" do diff --git a/spec/shell/color_spec.rb b/spec/shell/color_spec.rb index 4de414616..3f9d31aa7 100644 --- a/spec/shell/color_spec.rb +++ b/spec/shell/color_spec.rb @@ -32,9 +32,9 @@ def shell $stdin.should_receive(:gets).and_return('n') output = capture(:stdout){ shell.file_collision('spec/fixtures/doc/README'){ "README\nEND\n" } } - output.must =~ /\e\[31m\- __start__\e\[0m/ - output.must =~ /^ README/ - output.must =~ /\e\[32m\+ END\e\[0m/ + output.should =~ /\e\[31m\- __start__\e\[0m/ + output.should =~ /^ README/ + output.should =~ /\e\[32m\+ END\e\[0m/ end end end diff --git a/spec/shell_spec.rb b/spec/shell_spec.rb index 4bdf48511..846c8a223 100644 --- a/spec/shell_spec.rb +++ b/spec/shell_spec.rb @@ -8,30 +8,30 @@ def shell describe "#initialize" do it "sets shell value" do base = MyCounter.new [1, 2], { }, :shell => shell - base.shell.must == shell + base.shell.should == shell end it "sets the base value on the shell if an accessor is available" do base = MyCounter.new [1, 2], { }, :shell => shell - shell.base.must == base + shell.base.should == base end end describe "#shell" do it "returns the shell in use" do - MyCounter.new([1,2]).shell.must be_kind_of(Thor::Base.shell) + MyCounter.new([1,2]).shell.should be_kind_of(Thor::Base.shell) end it "uses $THOR_SHELL" do class Thor::Shell::TestShell < Thor::Shell::Basic; end - Thor::Base.shell.must == shell.class + Thor::Base.shell.should == shell.class ENV['THOR_SHELL'] = 'TestShell' Thor::Base.shell = nil - Thor::Base.shell.must == Thor::Shell::TestShell + Thor::Base.shell.should == Thor::Shell::TestShell ENV['THOR_SHELL'] = '' Thor::Base.shell = shell.class - Thor::Base.shell.must == shell.class + Thor::Base.shell.should == shell.class end end @@ -39,7 +39,7 @@ class Thor::Shell::TestShell < Thor::Shell::Basic; end it "uses padding for inside block outputs" do base = MyCounter.new([1,2]) base.with_padding do - capture(:stdout){ base.say_status :padding, "cool" }.strip.must == "padding cool" + capture(:stdout){ base.say_status :padding, "cool" }.strip.should == "padding cool" end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6ad72d3c2..ae93d2a59 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,7 +5,9 @@ require 'thor/group' require 'stringio' +require 'rcov' require 'rdoc' +require 'rspec' require 'diff/lcs' # You need diff/lcs installed to run specs (but not to run Thor). require 'fakeweb' # You need fakeweb installed to run specs (but not to run Thor). @@ -21,11 +23,6 @@ load File.join(File.dirname(__FILE__), "fixtures", "script.thor") load File.join(File.dirname(__FILE__), "fixtures", "invoke.thor") -Kernel.module_eval do - alias_method :must, :should - alias_method :must_not, :should_not -end - RSpec.configure do |config| def capture(stream) begin diff --git a/spec/task_spec.rb b/spec/task_spec.rb index 5adb157e7..45fb152bd 100644 --- a/spec/task_spec.rb +++ b/spec/task_spec.rb @@ -13,28 +13,28 @@ def task(options={}) it "includes namespace within usage" do Object.stub!(:namespace).and_return("foo") Object.stub!(:arguments).and_return([]) - task(:bar => :required).formatted_usage(Object).must == "foo:can_has --bar=BAR" + task(:bar => :required).formatted_usage(Object).should == "foo:can_has --bar=BAR" end it "removes default from namespace" do Object.stub!(:namespace).and_return("default:foo") Object.stub!(:arguments).and_return([]) - task(:bar => :required).formatted_usage(Object).must == ":foo:can_has --bar=BAR" + task(:bar => :required).formatted_usage(Object).should == ":foo:can_has --bar=BAR" end it "injects arguments into usage" do Object.stub!(:namespace).and_return("foo") Object.stub!(:arguments).and_return([ Thor::Argument.new(:bar, nil, true, :string) ]) - task(:foo => :required).formatted_usage(Object).must == "foo:can_has BAR --foo=FOO" + task(:foo => :required).formatted_usage(Object).should == "foo:can_has BAR --foo=FOO" end end describe "#dynamic" do it "creates a dynamic task with the given name" do - Thor::DynamicTask.new('task').name.must == 'task' - Thor::DynamicTask.new('task').description.must == 'A dynamically-generated task' - Thor::DynamicTask.new('task').usage.must == 'task' - Thor::DynamicTask.new('task').options.must == {} + Thor::DynamicTask.new('task').name.should == 'task' + Thor::DynamicTask.new('task').description.should == 'A dynamically-generated task' + Thor::DynamicTask.new('task').usage.should == 'task' + Thor::DynamicTask.new('task').options.should == {} end it "does not invoke an existing method" do @@ -48,7 +48,7 @@ def task(options={}) it "dup options hash" do task = Thor::Task.new("can_has", nil, nil, nil, :foo => true, :bar => :required) task.dup.options.delete(:foo) - task.options[:foo].must_not be_nil + task.options[:foo].should_not be_nil end end diff --git a/spec/thor_spec.rb b/spec/thor_spec.rb index cd6497f7b..280377ad6 100644 --- a/spec/thor_spec.rb +++ b/spec/thor_spec.rb @@ -5,67 +5,67 @@ it "sets options to the next method to be invoked" do args = ["foo", "bar", "--force"] arg, options = MyScript.start(args) - options.must == { "force" => true } + options.should == { "force" => true } end describe ":lazy_default" do it "is absent when option is not specified" do arg, options = MyScript.start(["with_optional"]) - options.must == {} + options.should == {} end it "sets a default that can be overridden for strings" do arg, options = MyScript.start(["with_optional", "--lazy"]) - options.must == { "lazy" => "yes" } + options.should == { "lazy" => "yes" } arg, options = MyScript.start(["with_optional", "--lazy", "yesyes!"]) - options.must == { "lazy" => "yesyes!" } + options.should == { "lazy" => "yesyes!" } end it "sets a default that can be overridden for numerics" do arg, options = MyScript.start(["with_optional", "--lazy-numeric"]) - options.must == { "lazy_numeric" => 42 } + options.should == { "lazy_numeric" => 42 } arg, options = MyScript.start(["with_optional", "--lazy-numeric", 20000]) - options.must == { "lazy_numeric" => 20000 } + options.should == { "lazy_numeric" => 20000 } end it "sets a default that can be overridden for arrays" do arg, options = MyScript.start(["with_optional", "--lazy-array"]) - options.must == { "lazy_array" => %w[eat at joes] } + options.should == { "lazy_array" => %w[eat at joes] } arg, options = MyScript.start(["with_optional", "--lazy-array", "hello", "there"]) - options.must == { "lazy_array" => %w[hello there] } + options.should == { "lazy_array" => %w[hello there] } end it "sets a default that can be overridden for hashes" do arg, options = MyScript.start(["with_optional", "--lazy-hash"]) - options.must == { "lazy_hash" => {'swedish' => 'meatballs'} } + options.should == { "lazy_hash" => {'swedish' => 'meatballs'} } arg, options = MyScript.start(["with_optional", "--lazy-hash", "polish:sausage"]) - options.must == { "lazy_hash" => {'polish' => 'sausage'} } + options.should == { "lazy_hash" => {'polish' => 'sausage'} } end end describe "when :for is supplied" do it "updates an already defined task" do args, options = MyChildScript.start(["animal", "horse", "--other=fish"]) - options[:other].must == "fish" + options[:other].should == "fish" end describe "and the target is on the parent class" do it "updates an already defined task" do args = ["example_default_task", "my_param", "--new-option=verified"] options = Scripts::MyScript.start(args) - options[:new_option].must == "verified" + options[:new_option].should == "verified" end it "adds a task to the tasks list if the updated task is on the parent class" do - Scripts::MyScript.tasks["example_default_task"].must_not be_nil + Scripts::MyScript.tasks["example_default_task"].should_not be_nil end it "clones the parent task" do - Scripts::MyScript.tasks["example_default_task"].must_not == MyChildScript.tasks["example_default_task"] + Scripts::MyScript.tasks["example_default_task"].should_not == MyChildScript.tasks["example_default_task"] end end end @@ -73,48 +73,48 @@ describe "#default_task" do it "sets a default task" do - MyScript.default_task.must == "example_default_task" + MyScript.default_task.should == "example_default_task" end it "invokes the default task if no command is specified" do - MyScript.start([]).must == "default task" + MyScript.start([]).should == "default task" end it "invokes the default task if no command is specified even if switches are given" do - MyScript.start(["--with", "option"]).must == {"with"=>"option"} + MyScript.start(["--with", "option"]).should == {"with"=>"option"} end it "inherits the default task from parent" do - MyChildScript.default_task.must == "example_default_task" + MyChildScript.default_task.should == "example_default_task" end end describe "#map" do it "calls the alias of a method if one is provided" do - MyScript.start(["-T", "fish"]).must == ["fish"] + MyScript.start(["-T", "fish"]).should == ["fish"] end it "calls the alias of a method if several are provided via .map" do - MyScript.start(["-f", "fish"]).must == ["fish", {}] - MyScript.start(["--foo", "fish"]).must == ["fish", {}] + MyScript.start(["-f", "fish"]).should == ["fish", {}] + MyScript.start(["--foo", "fish"]).should == ["fish", {}] end it "inherits all mappings from parent" do - MyChildScript.default_task.must == "example_default_task" + MyChildScript.default_task.should == "example_default_task" end end describe "#desc" do it "provides description for a task" do content = capture(:stdout) { MyScript.start(["help"]) } - content.must =~ /thor my_script:zoo\s+# zoo around/m + content.should =~ /thor my_script:zoo\s+# zoo around/m end it "provides no namespace if $thor_runner is false" do begin $thor_runner = false content = capture(:stdout) { MyScript.start(["help"]) } - content.must =~ /thor zoo\s+# zoo around/m + content.should =~ /thor zoo\s+# zoo around/m ensure $thor_runner = true end @@ -122,17 +122,17 @@ describe "when :for is supplied" do it "overwrites a previous defined task" do - capture(:stdout) { MyChildScript.start(["help"]) }.must =~ /animal KIND \s+# fish around/m + capture(:stdout) { MyChildScript.start(["help"]) }.should =~ /animal KIND \s+# fish around/m end end describe "when :hide is supplied" do it "does not show the task in help" do - capture(:stdout) { MyScript.start(["help"]) }.must_not =~ /this is hidden/m + capture(:stdout) { MyScript.start(["help"]) }.should_not =~ /this is hidden/m end it "but the task is still invokcable not show the task in help" do - MyScript.start(["hidden", "yesyes"]).must == ["yesyes"] + MyScript.start(["hidden", "yesyes"]).should == ["yesyes"] end end end @@ -140,79 +140,79 @@ describe "#method_options" do it "sets default options if called before an initializer" do options = MyChildScript.class_options - options[:force].type.must == :boolean - options[:param].type.must == :numeric + options[:force].type.should == :boolean + options[:param].type.should == :numeric end it "overwrites default options if called on the method scope" do args = ["zoo", "--force", "--param", "feathers"] options = MyChildScript.start(args) - options.must == { "force" => true, "param" => "feathers" } + options.should == { "force" => true, "param" => "feathers" } end it "allows default options to be merged with method options" do args = ["animal", "bird", "--force", "--param", "1.0", "--other", "tweets"] arg, options = MyChildScript.start(args) - arg.must == 'bird' - options.must == { "force"=>true, "param"=>1.0, "other"=>"tweets" } + arg.should == 'bird' + options.should == { "force"=>true, "param"=>1.0, "other"=>"tweets" } end end describe "#start" do it "calls a no-param method when no params are passed" do - MyScript.start(["zoo"]).must == true + MyScript.start(["zoo"]).should == true end it "calls a single-param method when a single param is passed" do - MyScript.start(["animal", "fish"]).must == ["fish"] + MyScript.start(["animal", "fish"]).should == ["fish"] end it "does not set options in attributes" do - MyScript.start(["with_optional", "--all"]).must == [nil, { "all" => true }] + MyScript.start(["with_optional", "--all"]).should == [nil, { "all" => true }] end it "raises an error if a required param is not provided" do - capture(:stderr) { MyScript.start(["animal"]) }.strip.must == '"animal" was called incorrectly. Call as "thor my_script:animal TYPE".' + capture(:stderr) { MyScript.start(["animal"]) }.strip.should == '"animal" was called incorrectly. Call as "thor my_script:animal TYPE".' end it "raises an error if the invoked task does not exist" do - capture(:stderr) { Amazing.start(["animal"]) }.strip.must == 'Could not find task "animal" in "amazing" namespace.' + capture(:stderr) { Amazing.start(["animal"]) }.strip.should == 'Could not find task "animal" in "amazing" namespace.' end it "calls method_missing if an unknown method is passed in" do - MyScript.start(["unk", "hello"]).must == [:unk, ["hello"]] + MyScript.start(["unk", "hello"]).should == [:unk, ["hello"]] end it "does not call a private method no matter what" do - capture(:stderr) { MyScript.start(["what"]) }.strip.must == 'Could not find task "what" in "my_script" namespace.' + capture(:stderr) { MyScript.start(["what"]) }.strip.should == 'Could not find task "what" in "my_script" namespace.' end it "uses task default options" do options = MyChildScript.start(["animal", "fish"]).last - options.must == { "other" => "method default" } + options.should == { "other" => "method default" } end it "raises when an exception happens within the task call" do - lambda { MyScript.start(["call_myself_with_wrong_arity"]) }.must raise_error(ArgumentError) + lambda { MyScript.start(["call_myself_with_wrong_arity"]) }.should raise_error(ArgumentError) end end describe "#subcommand" do it "maps a given subcommand to another Thor subclass" do barn_help = capture(:stdout){ Scripts::MyDefaults.start(["barn"]) } - barn_help.must include("barn help [COMMAND] # Describe subcommands or one specific subcommand") + barn_help.should include("barn help [COMMAND] # Describe subcommands or one specific subcommand") end it "passes commands to subcommand classes" do - capture(:stdout){ Scripts::MyDefaults.start(["barn", "open"]) }.strip.must == "Open sesame!" + capture(:stdout){ Scripts::MyDefaults.start(["barn", "open"]) }.strip.should == "Open sesame!" end it "passes arguments to subcommand classes" do - capture(:stdout){ Scripts::MyDefaults.start(["barn", "open", "shotgun"]) }.strip.must == "That's going to leave a mark." + capture(:stdout){ Scripts::MyDefaults.start(["barn", "open", "shotgun"]) }.strip.should == "That's going to leave a mark." end it "ignores unknown options (the subcommand class will handle them)" do - capture(:stdout){ Scripts::MyDefaults.start(["barn", "paint", "blue", "--coats", "4"])}.strip.must == "4 coats of blue paint" + capture(:stdout){ Scripts::MyDefaults.start(["barn", "paint", "blue", "--coats", "4"])}.strip.should == "4 coats of blue paint" end end @@ -227,43 +227,43 @@ def shell end it "provides useful help info for the help method itself" do - @content.must =~ /help \[TASK\]\s+# Describe available tasks/ + @content.should =~ /help \[TASK\]\s+# Describe available tasks/ end it "provides useful help info for a method with params" do - @content.must =~ /animal TYPE\s+# horse around/ + @content.should =~ /animal TYPE\s+# horse around/ end it "uses the maximum terminal size to show tasks" do @shell.should_receive(:terminal_width).and_return(80) content = capture(:stdout){ MyScript.help(shell) } - content.must =~ /aaa\.\.\.$/ + content.should =~ /aaa\.\.\.$/ end it "provides description for tasks from classes in the same namespace" do - @content.must =~ /baz\s+# do some bazing/ + @content.should =~ /baz\s+# do some bazing/ end it "shows superclass tasks" do content = capture(:stdout){ MyChildScript.help(shell) } - content.must =~ /foo BAR \s+# do some fooing/ + content.should =~ /foo BAR \s+# do some fooing/ end it "shows class options information" do content = capture(:stdout){ MyChildScript.help(shell) } - content.must =~ /Options\:/ - content.must =~ /\[\-\-param=N\]/ + content.should =~ /Options\:/ + content.should =~ /\[\-\-param=N\]/ end it "injects class arguments into default usage" do content = capture(:stdout){ Scripts::MyScript.help(shell) } - content.must =~ /zoo ACCESSOR \-\-param\=PARAM/ + content.should =~ /zoo ACCESSOR \-\-param\=PARAM/ end end describe "for a specific task" do it "provides full help info when talking about a specific task" do - capture(:stdout) { MyScript.task_help(shell, "foo") }.must == <<-END + capture(:stdout) { MyScript.task_help(shell, "foo") }.should == <<-END Usage: thor my_script:foo BAR @@ -279,15 +279,15 @@ def shell it "raises an error if the task can't be found" do lambda { MyScript.task_help(shell, "unknown") - }.must raise_error(Thor::UndefinedTaskError, 'Could not find task "unknown" in "my_script" namespace.') + }.should raise_error(Thor::UndefinedTaskError, 'Could not find task "unknown" in "my_script" namespace.') end it "normalizes names before claiming they don't exist" do - capture(:stdout) { MyScript.task_help(shell, "name-with-dashes") }.must =~ /thor my_script:name-with-dashes/ + capture(:stdout) { MyScript.task_help(shell, "name-with-dashes") }.should =~ /thor my_script:name-with-dashes/ end it "uses the long description if it exists" do - capture(:stdout) { MyScript.task_help(shell, "long_description") }.must == <<-HELP + capture(:stdout) { MyScript.task_help(shell, "long_description") }.should == <<-HELP Usage: thor my_script:long_description @@ -301,17 +301,17 @@ def shell it "doesn't assign the long description to the next task without one" do capture(:stdout) do MyScript.task_help(shell, "name_with_dashes") - end.must_not =~ /so very long/i + end.should_not =~ /so very long/i end end describe "instance method" do it "calls the class method" do - capture(:stdout){ MyScript.start(["help"]) }.must =~ /Tasks:/ + capture(:stdout){ MyScript.start(["help"]) }.should =~ /Tasks:/ end it "calls the class method" do - capture(:stdout){ MyScript.start(["help", "foo"]) }.must =~ /Usage:/ + capture(:stdout){ MyScript.start(["help", "foo"]) }.should =~ /Usage:/ end end end @@ -321,14 +321,14 @@ def shell capture(:stdout) { klass = Class.new(Thor) klass.class_eval "def hello_from_thor; end" - }.must =~ /\[WARNING\] Attempted to create task "hello_from_thor" without usage or description/ + }.should =~ /\[WARNING\] Attempted to create task "hello_from_thor" without usage or description/ end it "does not print if overwriting a previous task" do capture(:stdout) { klass = Class.new(Thor) klass.class_eval "def help; end" - }.must be_empty + }.should be_empty end end end diff --git a/spec/util_spec.rb b/spec/util_spec.rb index a938ccffc..4da7c64d4 100644 --- a/spec/util_spec.rb +++ b/spec/util_spec.rb @@ -9,112 +9,112 @@ def self.clear_user_home! describe Thor::Util do describe "#find_by_namespace" do it "returns 'default' if no namespace is given" do - Thor::Util.find_by_namespace('').must == Scripts::MyDefaults + Thor::Util.find_by_namespace('').should == Scripts::MyDefaults end it "adds 'default' if namespace starts with :" do - Thor::Util.find_by_namespace(':child').must == Scripts::ChildDefault + Thor::Util.find_by_namespace(':child').should == Scripts::ChildDefault end it "returns nil if the namespace can't be found" do - Thor::Util.find_by_namespace('thor:core_ext:ordered_hash').must be_nil + Thor::Util.find_by_namespace('thor:core_ext:ordered_hash').should be_nil end it "returns a class if it matches the namespace" do - Thor::Util.find_by_namespace('app:broken:counter').must == BrokenCounter + Thor::Util.find_by_namespace('app:broken:counter').should == BrokenCounter end it "matches classes default namespace" do - Thor::Util.find_by_namespace('scripts:my_script').must == Scripts::MyScript + Thor::Util.find_by_namespace('scripts:my_script').should == Scripts::MyScript end end describe "#namespace_from_thor_class" do it "replaces constant nesting with task namespacing" do - Thor::Util.namespace_from_thor_class("Foo::Bar::Baz").must == "foo:bar:baz" + Thor::Util.namespace_from_thor_class("Foo::Bar::Baz").should == "foo:bar:baz" end it "snake-cases component strings" do - Thor::Util.namespace_from_thor_class("FooBar::BarBaz::BazBoom").must == "foo_bar:bar_baz:baz_boom" + Thor::Util.namespace_from_thor_class("FooBar::BarBaz::BazBoom").should == "foo_bar:bar_baz:baz_boom" end it "accepts class and module objects" do - Thor::Util.namespace_from_thor_class(Thor::CoreExt::OrderedHash).must == "thor:core_ext:ordered_hash" - Thor::Util.namespace_from_thor_class(Thor::Util).must == "thor:util" + Thor::Util.namespace_from_thor_class(Thor::CoreExt::OrderedHash).should == "thor:core_ext:ordered_hash" + Thor::Util.namespace_from_thor_class(Thor::Util).should == "thor:util" end it "removes Thor::Sandbox namespace" do - Thor::Util.namespace_from_thor_class("Thor::Sandbox::Package").must == "package" + Thor::Util.namespace_from_thor_class("Thor::Sandbox::Package").should == "package" end end describe "#namespaces_in_content" do it "returns an array of names of constants defined in the string" do list = Thor::Util.namespaces_in_content("class Foo; class Bar < Thor; end; end; class Baz; class Bat; end; end") - list.must include("foo:bar") - list.must_not include("bar:bat") + list.should include("foo:bar") + list.should_not include("bar:bat") end it "doesn't put the newly-defined constants in the enclosing namespace" do Thor::Util.namespaces_in_content("class Blat; end") - defined?(Blat).must_not be - defined?(Thor::Sandbox::Blat).must be + defined?(Blat).should_not be + defined?(Thor::Sandbox::Blat).should be end end describe "#snake_case" do it "preserves no-cap strings" do - Thor::Util.snake_case("foo").must == "foo" - Thor::Util.snake_case("foo_bar").must == "foo_bar" + Thor::Util.snake_case("foo").should == "foo" + Thor::Util.snake_case("foo_bar").should == "foo_bar" end it "downcases all-caps strings" do - Thor::Util.snake_case("FOO").must == "foo" - Thor::Util.snake_case("FOO_BAR").must == "foo_bar" + Thor::Util.snake_case("FOO").should == "foo" + Thor::Util.snake_case("FOO_BAR").should == "foo_bar" end it "downcases initial-cap strings" do - Thor::Util.snake_case("Foo").must == "foo" + Thor::Util.snake_case("Foo").should == "foo" end it "replaces camel-casing with underscores" do - Thor::Util.snake_case("FooBarBaz").must == "foo_bar_baz" - Thor::Util.snake_case("Foo_BarBaz").must == "foo_bar_baz" + Thor::Util.snake_case("FooBarBaz").should == "foo_bar_baz" + Thor::Util.snake_case("Foo_BarBaz").should == "foo_bar_baz" end it "places underscores between multiple capitals" do - Thor::Util.snake_case("ABClass").must == "a_b_class" + Thor::Util.snake_case("ABClass").should == "a_b_class" end end describe "#find_class_and_task_by_namespace" do it "returns a Thor::Group class if full namespace matches" do - Thor::Util.find_class_and_task_by_namespace("my_counter").must == [MyCounter, nil] + Thor::Util.find_class_and_task_by_namespace("my_counter").should == [MyCounter, nil] end it "returns a Thor class if full namespace matches" do - Thor::Util.find_class_and_task_by_namespace("thor").must == [Thor, nil] + Thor::Util.find_class_and_task_by_namespace("thor").should == [Thor, nil] end it "returns a Thor class and the task name" do - Thor::Util.find_class_and_task_by_namespace("thor:help").must == [Thor, "help"] + Thor::Util.find_class_and_task_by_namespace("thor:help").should == [Thor, "help"] end it "falls back in the namespace:task look up even if a full namespace does not match" do Thor.const_set(:Help, Module.new) - Thor::Util.find_class_and_task_by_namespace("thor:help").must == [Thor, "help"] + Thor::Util.find_class_and_task_by_namespace("thor:help").should == [Thor, "help"] Thor.send :remove_const, :Help end it "falls back on the default namespace class if nothing else matches" do - Thor::Util.find_class_and_task_by_namespace("test").must == [Scripts::MyDefaults, "test"] + Thor::Util.find_class_and_task_by_namespace("test").should == [Scripts::MyDefaults, "test"] end end describe "#thor_classes_in" do it "returns thor classes inside the given class" do - Thor::Util.thor_classes_in(MyScript).must == [MyScript::AnotherScript] - Thor::Util.thor_classes_in(MyScript::AnotherScript).must be_empty + Thor::Util.thor_classes_in(MyScript).should == [MyScript::AnotherScript] + Thor::Util.thor_classes_in(MyScript::AnotherScript).should be_empty end end @@ -125,14 +125,14 @@ def self.clear_user_home! end it "returns the user path if none variable is set on the environment" do - Thor::Util.user_home.must == File.expand_path("~") + Thor::Util.user_home.should == File.expand_path("~") end it "returns the *unix system path if file cannot be expanded and separator does not exist" do File.should_receive(:expand_path).with("~").and_raise(RuntimeError) previous_value = File::ALT_SEPARATOR capture(:stderr){ File.const_set(:ALT_SEPARATOR, false) } - Thor::Util.user_home.must == "/" + Thor::Util.user_home.should == "/" capture(:stderr){ File.const_set(:ALT_SEPARATOR, previous_value) } end @@ -140,24 +140,24 @@ def self.clear_user_home! File.should_receive(:expand_path).with("~").and_raise(RuntimeError) previous_value = File::ALT_SEPARATOR capture(:stderr){ File.const_set(:ALT_SEPARATOR, true) } - Thor::Util.user_home.must == "C:/" + Thor::Util.user_home.should == "C:/" capture(:stderr){ File.const_set(:ALT_SEPARATOR, previous_value) } end it "returns HOME/.thor if set" do ENV.stub!(:[]).with("HOME").and_return("/home/user/") - Thor::Util.user_home.must == "/home/user/" + Thor::Util.user_home.should == "/home/user/" end it "returns path with HOMEDRIVE and HOMEPATH if set" do ENV.stub!(:[]).with("HOMEDRIVE").and_return("D:/") ENV.stub!(:[]).with("HOMEPATH").and_return("Documents and Settings/James") - Thor::Util.user_home.must == "D:/Documents and Settings/James" + Thor::Util.user_home.should == "D:/Documents and Settings/James" end it "returns APPDATA/.thor if set" do ENV.stub!(:[]).with("APPDATA").and_return("/home/user/") - Thor::Util.user_home.must == "/home/user/" + Thor::Util.user_home.should == "/home/user/" end end end