Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bye bye RR. Hello Rspec mocks.

  • Loading branch information...
commit a72d0f482104d3e49e775af5acdeb9e3b78266cb 1 parent f32bdbf
@josevalim josevalim authored
View
6 lib/thor/task.rb
@@ -53,7 +53,7 @@ def formatted_usage(klass, namespace=nil)
# Add usage with required arguments
formatted << if klass && !klass.arguments.empty?
usage.to_s.gsub(/^#{name}/) do |match|
- match << " " << required_arguments(klass)
+ match << " " << klass.arguments.map{ |a| a.usage }.compact.join(' ')
end
else
usage.to_s
@@ -68,10 +68,6 @@ def formatted_usage(klass, namespace=nil)
protected
- def required_arguments(klass)
- klass.arguments.map{ |a| a.usage if a.required? }.compact.join(' ')
- end
-
def required_options
@required_options ||= options.map{ |_, o| o.usage if o.required? }.compact.sort.join(" ")
end
View
14 spec/actions/create_file_spec.rb
@@ -8,7 +8,7 @@
def create_file(destination=nil, config={}, options={})
@base = MyCounter.new([1,2], options, { :destination_root => destination_root })
- stub(@base).file_name { 'rdoc' }
+ @base.stub!(:file_name).and_return('rdoc')
@action = Thor::Actions::CreateFile.new(@base, destination, "CONFIGURATION",
{ :verbose => !@silence }.merge(config))
@@ -103,7 +103,7 @@ def silence!
it "shows conflict status to ther user" do
create_file("doc/config.rb").must_not be_identical
- mock($stdin).gets{ 's' }
+ $stdin.should_receive(:gets).and_return('s')
file = File.join(destination_root, 'doc/config.rb')
content = invoke!
@@ -114,21 +114,21 @@ def silence!
it "creates the file if the file collision menu returns true" do
create_file("doc/config.rb")
- mock($stdin).gets{ 'y' }
+ $stdin.should_receive(:gets).and_return('y')
invoke!.must =~ /force doc\/config\.rb/
end
it "skips the file if the file collision menu returns false" do
create_file("doc/config.rb")
- mock($stdin).gets{ 'n' }
+ $stdin.should_receive(:gets).and_return('n')
invoke!.must =~ /skip doc\/config\.rb/
end
it "executes the block given to show file content" do
create_file("doc/config.rb")
- mock($stdin).gets{ 'd' }
- mock($stdin).gets{ 'n' }
- mock(@base.shell).system(/diff -u/)
+ $stdin.should_receive(:gets).and_return('d')
+ $stdin.should_receive(:gets).and_return('n')
+ @base.shell.should_receive(:system).with(/diff -u/)
invoke!
end
end
View
10 spec/actions/file_manipulation_spec.rb
@@ -29,23 +29,23 @@ def file
describe "#chmod" do
it "executes the command given" do
- mock(FileUtils).chmod_R(0755, file)
+ FileUtils.should_receive(:chmod_R).with(0755, file)
action :chmod, "foo", 0755
end
it "does not execute the command if pretending given" do
- dont_allow(FileUtils).chmod_R(0755, file)
+ FileUtils.should_not_receive(:chmod_R)
runner(:pretend => true)
action :chmod, "foo", 0755
end
it "logs status" do
- mock(FileUtils).chmod_R(0755, file)
+ FileUtils.should_receive(:chmod_R).with(0755, file)
action(:chmod, "foo", 0755).must == " chmod foo\n"
end
it "does not log status if required" do
- mock(FileUtils).chmod_R(0755, file)
+ FileUtils.should_receive(:chmod_R).with(0755, file)
action(:chmod, "foo", 0755, :verbose => false).must be_empty
end
end
@@ -123,7 +123,7 @@ def file
end
it "converts enconded instructions" do
- mock(runner).file_name{ "rdoc" }
+ 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
View
8 spec/group_spec.rb
@@ -29,7 +29,7 @@
end
it "invokes help message if any of the shortcuts is given" do
- stub(MyCounter).help
+ MyCounter.should_receive(:help)
MyCounter.start(["-h"])
end
end
@@ -66,12 +66,6 @@
@content.must =~ /Options/
@content.must =~ /\[\-\-third=THREE\]/
end
-
- it "shows only usage if a short help is required" do
- content = capture(:stdout){ MyCounter.help(Thor::Base.shell.new, :short => true) }
- content.must =~ /my_counter N \[N\]/
- content.must_not =~ /Options/
- end
end
describe "#invoke" do
Please sign in to comment.
Something went wrong with that request. Please try again.