spec/option_spec.rb in rprogram-0.3.1 vs spec/option_spec.rb in rprogram-0.3.2
- old
+ new
@@ -1,169 +1,167 @@
-require 'rprogram/option'
-
require 'spec_helper'
require 'option_examples'
+require 'rprogram/option'
+
describe Option do
describe "custom formatting" do
it "should allow the format block to return nil" do
- opt = Option.new(:flag => '-f') { |opt,value| }
+ opt = described_class.new(:flag => '-f') { |opt,value| }
opt.arguments('bla').should == []
end
end
describe "single flag" do
- before(:all) do
- @option = Option.new(:flag => '-f')
- end
+ subject { described_class.new(:flag => '-f') }
it_should_behave_like 'Option'
it "should render a single flag with an optional value" do
value = 'foo'
- @option.arguments('foo').should == ['-f', 'foo']
+ subject.arguments('foo').should == ['-f', 'foo']
end
it "should render a single flag with multiple values" do
value = ['foo','bar','baz']
- @option.arguments(value).should == ['-f','foo','bar','baz']
+ subject.arguments(value).should == ['-f','foo','bar','baz']
end
it "should render a single flag with a Hash of keys" do
value = {:foo => true, :bar => false}
- @option.arguments(value).should == ['-f','foo']
+ subject.arguments(value).should == ['-f','foo']
end
it "should render a single flag with a Hash of keys and values" do
value = {:foo => 'bar'}
- @option.arguments(value).should == ['-f','foo=bar']
+ subject.arguments(value).should == ['-f','foo=bar']
end
end
describe "equals flag" do
- before(:all) do
- @option = Option.new(:equals => true, :flag => '-f')
+ subject do
+ described_class.new(:equals => true, :flag => '-f')
end
it_should_behave_like 'Option'
it "should render a single flag with a value" do
value = 'foo'
- @option.arguments('foo').should == ['-f=foo']
+ subject.arguments('foo').should == ['-f=foo']
end
it "should render a single flag with multiple values" do
value = ['foo', 'bar', 'baz']
- @option.arguments(value).should == ['-f=foo bar baz']
+ subject.arguments(value).should == ['-f=foo bar baz']
end
it "should render a single flag with a Hash of keys" do
value = {:foo => true, :bar => false}
- @option.arguments(value).should == ['-f=foo']
+ subject.arguments(value).should == ['-f=foo']
end
end
describe "multiple flags" do
- before(:all) do
- @option = Option.new(:multiple => true, :flag => '-f')
+ subject do
+ described_class.new(:multiple => true, :flag => '-f')
end
it_should_behave_like 'Option'
it "should render a single flag with a value" do
value = 'foo'
- @option.arguments(value).should == ['-f', 'foo']
+ subject.arguments(value).should == ['-f', 'foo']
end
it "should render multiple flags for multiple values" do
value = ['foo','bar','baz']
- @option.arguments(value).should == ['-f', 'foo', '-f', 'bar', '-f', 'baz']
+ subject.arguments(value).should == ['-f', 'foo', '-f', 'bar', '-f', 'baz']
end
it "should render multiple flags for a Hash of keys" do
value = {:foo => true, :bar => true, :baz => false}
- args = @option.arguments(value)
+ args = subject.arguments(value)
(args & ['-f', 'foo']).should == ['-f', 'foo']
(args & ['-f', 'bar']).should == ['-f', 'bar']
end
it "should render multiple flags for a Hash of values" do
value = {:foo => 'bar'}
- @option.arguments(value).should == ['-f', 'foo=bar']
+ subject.arguments(value).should == ['-f', 'foo=bar']
end
end
describe "multiple equals flags" do
- before(:all) do
- @option = Option.new(:multiple => true, :equals => true, :flag => '-f')
+ subject do
+ described_class.new(:multiple => true, :equals => true, :flag => '-f')
end
it_should_behave_like 'Option'
it "should render a single flag with a value" do
value = 'foo'
- @option.arguments(value).should == ['-f=foo']
+ subject.arguments(value).should == ['-f=foo']
end
it "should render multiple equal flags for multiple values" do
value = ['foo', 'bar']
- @option.arguments(value).should == ['-f=foo', '-f=bar']
+ subject.arguments(value).should == ['-f=foo', '-f=bar']
end
it "should render multiple equal flags for a Hash of keys" do
value = {:foo => true, :bar => true, :baz => false}
- args = @option.arguments(value)
+ args = subject.arguments(value)
args.include?('-f=foo').should == true
args.include?('-f=bar').should == true
end
it "should render multiple equal flags for a Hash of values" do
value = {:foo => 'bar', :bar => 'baz'}
- args = @option.arguments(value)
+ args = subject.arguments(value)
args.include?('-f=foo=bar').should == true
args.include?('-f=bar=baz').should == true
end
end
describe "separated values" do
- before(:all) do
- @option = Option.new(:separator => ',', :flag => '-f')
+ subject do
+ described_class.new(:separator => ',', :flag => '-f')
end
it_should_behave_like 'Option'
it "should render a single flag with a value" do
value = 'foo'
- @option.arguments('foo').should == ['-f', 'foo']
+ subject.arguments('foo').should == ['-f', 'foo']
end
it "should render a single flag with multiple values" do
value = ['foo', 'bar', 'baz']
- @option.arguments(value).should == ['-f', 'foo,bar,baz']
+ subject.arguments(value).should == ['-f', 'foo,bar,baz']
end
it "should render a single flag with a Hash of keys" do
value = {:foo => true, :bar => true, :baz => false}
- args = @option.arguments(value)
+ args = subject.arguments(value)
args[0].should == '-f'
sub_args = args[1].split(',')
@@ -171,10 +169,10 @@
sub_args.include?('bar').should == true
end
it "should render a single flag with a Hash of values" do
value = {:foo => 'bar', :bar => 'baz'}
- args = @option.arguments(value)
+ args = subject.arguments(value)
args[0].should == '-f'
sub_args = args[1].split(',')