test/scientist_test.rb in boson-0.1.0 vs test/scientist_test.rb in boson-0.2.0
- old
+ new
@@ -1,10 +1,12 @@
require File.join(File.dirname(__FILE__), 'test_helper')
module Boson
class ScientistTest < Test::Unit::TestCase
before(:all) {
+ unless ScientistTest.const_defined?(:Blah)
+ Boson.send :remove_const, :BinRunner if Boson.const_defined?(:BinRunner)
eval <<-EOF
module Blah
def blah(arg1, options={})
[arg1, options]
end
@@ -13,12 +15,16 @@
end
def default_blah(arg1, arg2=default, options={})
[arg1, arg2, options]
end
def default; 'some default'; end
+ def default_option(options={})
+ options
+ end
end
EOF
+ end
@opt_cmd = Object.new.extend Blah
}
def command(hash, args)
hash = {:name=>'blah', :lib=>'bling', :options=>{:force=>:boolean, :level=>2}}.merge(hash)
@@ -124,11 +130,11 @@
test "with option error" do
capture_stderr { command_with_args('a1 -l') }.should =~ /Error.*level/
end
test "with unexpected error in translation" do
- Scientist.expects(:command_options).raises("unexpected")
+ Scientist.expects(:parse_command_options).raises("unexpected")
capture_stderr { command_with_args('a1') }.should =~ /Error.*unexpected/
end
test "with unexpected error in render" do
Scientist.expects(:render?).raises("unexpected")
@@ -185,11 +191,11 @@
def command_with_render(*args)
basic_command({:render_options=>{:fields=>{:values=>['f1', 'f2']}} }, args)
end
def render_expected(options=nil)
- View.expects(:render).with(anything, options || anything)
+ View.expects(:render).with(anything, options || anything, false)
end
context "render" do
test "called for command with render_options" do
render_expected
@@ -233,9 +239,39 @@
test "with non-hash user-defined render options" do
render_expected :fields=>['f1'], :foo=>true
args = ["--foo --fields f1 ab"]
basic_command({:render_options=>{:foo=>:boolean, :fields=>%w{f1 f2 f3}} }, args)
+ end
+ end
+
+ context "command with default option" do
+ before(:all) { @cmd_attributes = {:name=>'default_option', :default_option=>'level', :args=>1} }
+
+ test "parses normally from irb" do
+ command(@cmd_attributes, '-f --level=3').should == {:level=>3, :force=>true}
+ end
+
+ test "parses normally from cmdline" do
+ Boson.expects(:const_defined?).returns true
+ command(@cmd_attributes, ['--force', '--level=3']).should == {:level=>3, :force=>true}
+ end
+
+ test "parses no arguments normally" do
+ command(@cmd_attributes, '').should == {:level=>2}
+ end
+
+ test "parses ruby arguments normally" do
+ command(@cmd_attributes, [{:force=>true, :level=>10}]).should == {:level=>10, :force=>true}
+ end
+
+ test "prepends correctly from irb" do
+ command(@cmd_attributes, '3 -f').should == {:level=>3, :force=>true}
+ end
+
+ test "prepends correctly from cmdline" do
+ Boson.expects(:const_defined?).returns true
+ command(@cmd_attributes, ['3','-f']).should == {:level=>3, :force=>true}
end
end
test "optionless command renders" do
render_expected :fields=>['f1']