spec/checkbox_group_spec.rb in domkey-0.2.0 vs spec/checkbox_group_spec.rb in domkey-0.3.0
- old
+ new
@@ -37,33 +37,37 @@
@v.group.to_a.each { |e| e.should be_kind_of(Domkey::View::PageObject) }
end
it 'initial value on test page' do
@v.group.value.should eql ['other']
+ @v.group.value(:value, :index, :label).should eql [value: 'other', index: 2, label: 'Other']
end
- it 'set value attribute by default. value returns array of value attribute' do
+ it 'set string' do
@v.group.set 'tomato'
@v.group.value.should eql ['tomato']
+ end
+
+ it 'set regexp' do
@v.group.set /^othe/
@v.group.value.should eql ['other']
end
- it 'set array of value attribute. value returns array of value attribute' do
+ it 'set array of strings or regexp' do
@v.group.set ['tomato']
@v.group.value.should eql ['tomato']
@v.group.set ['other', /tomat/]
@v.group.value.should eql ['tomato', 'other']
end
- it 'set false clears all. value is empty array' do
+ it 'set false clears all' do
@v.group.set false
@v.group.value.should eql []
end
- it 'set empty array clears all. value is empty array' do
+ it 'set empty array clears all' do
@v.group.set []
@v.group.value.should eql []
end
it 'set value string not found error' do
@@ -72,10 +76,82 @@
it 'set value regexp not found error' do
expect { @v.group.set /balaba/ }.to raise_error
end
- it 'options' do
+ it 'set by index single' do
+ @v.group.set index: 1
+ @v.group.value.should eql ['tomato']
+ end
+
+ it 'set by index array' do
+ @v.group.set index: [0, 2, 1]
+ @v.group.value.should eql ['cucumber', 'tomato', 'other']
+ end
+
+ it 'set by label string' do
+ @v.group.set label: 'Tomatorama'
+ @v.group.value.should eql ['tomato']
+ end
+
+ it 'set by label regexp' do
+ @v.group.set label: /umberama/
+ @v.group.value([:index, :value, :text, :label]).should eql [{:index=>0, :value=>"cucumber", :text=>"Cucumberama", :label=>"Cucumberama"}]
+ end
+
+
+ it 'set by index array string, regex' do
+ @v.group.set label: ['Cucumberama', /atorama/]
+ @v.group.value.should eql ['cucumber', 'tomato']
+ end
+
+
+ it 'value options single selected' do
+ @v.group.set [/tomat/]
+ @v.group.value.should eql ['tomato']
+
+ @v.group.value(:label).should eql [{:label=>"Tomatorama"}]
+ @v.group.value([:label]).should eql [{:label=>"Tomatorama"}]
+ @v.group.value(:label, :value, :index).should eql [{:label=>"Tomatorama", :value=>"tomato", :index=>1}]
+ end
+
+ it 'value options many selected' do
+ @v.group.set ['other', /tomat/, /cucum/]
+ @v.group.value.should eql ['cucumber', 'tomato', 'other']
+
+ @v.group.value(:label).should eql [{:label=>"Cucumberama"}, {:label=>"Tomatorama"}, {:label=>"Other"}]
+ @v.group.value(:label, :index, :value).should eql [{:label=>"Cucumberama", :index=>0, :value=>"cucumber"},
+ {:label=>"Tomatorama", :index=>1, :value=>"tomato"},
+ {:label=>"Other", :index=>2, :value=>"other"}]
+ end
+
+ it 'value options none selected' do
+ @v.group.set []
+ @v.group.value.should eql []
+ @v.group.value(:label).should eql []
+ @v.group.value(:label, :index, :value).should eql []
+ end
+
+ it 'options by default' do
@v.group.options.should eql ["cucumber", "tomato", "other"]
+ end
+
+ it 'options by opts single' do
+ @v.group.options(:value).should eql [{:value=>"cucumber"}, {:value=>"tomato"}, {:value=>"other"}]
+ @v.group.options([:value]).should eql [{:value=>"cucumber"}, {:value=>"tomato"}, {:value=>"other"}]
+ end
+
+ it 'options by label' do
+ @v.group.options(:label).should eql [{:label=>"Cucumberama"}, {:label=>"Tomatorama"}, {:label=>"Other"}]
+ @v.group.options([:label]).should eql [{:label=>"Cucumberama"}, {:label=>"Tomatorama"}, {:label=>"Other"}]
+ end
+
+ it 'options by opts many' do
+ expected = [{:value=>"cucumber", :index=>0, :label=>"Cucumberama", :text=>"Cucumberama"},
+ {:value=>"tomato", :index=>1, :label=>"Tomatorama", :text=>"Tomatorama"},
+ {:value=>"other", :index=>2, :label=>"Other", :text=>"Other"}]
+
+ @v.group.options(:value, :index, :label, :text).should eql expected
+ @v.group.options([:value, :index, :label, :text]).should eql expected
end
end
end
\ No newline at end of file