few components with rspec3 syntax
This commit is contained in:
parent
c96220ca76
commit
0fd98b56d8
97 changed files with 1620 additions and 1618 deletions
|
@ -5,8 +5,8 @@ describe StringSettingValidator do
|
|||
describe '#valid_value?' do
|
||||
shared_examples "for all StringSettingValidator opts" do
|
||||
it "returns true for blank values" do
|
||||
validator.valid_value?('').should == true
|
||||
validator.valid_value?(nil).should == true
|
||||
expect(validator.valid_value?('')).to eq(true)
|
||||
expect(validator.valid_value?(nil)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -16,21 +16,21 @@ describe StringSettingValidator do
|
|||
include_examples "for all StringSettingValidator opts"
|
||||
|
||||
it "returns true if value matches the regex" do
|
||||
validator.valid_value?('The bacon is delicious').should == true
|
||||
expect(validator.valid_value?('The bacon is delicious')).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if the value doesn't match the regex" do
|
||||
validator.valid_value?('The vegetables are delicious').should == false
|
||||
expect(validator.valid_value?('The vegetables are delicious')).to eq(false)
|
||||
end
|
||||
|
||||
it "test some other regexes" do
|
||||
v = described_class.new(regex: '^(chocolate|banana)$')
|
||||
v.valid_value?('chocolate').should == true
|
||||
v.valid_value?('chocolates').should == false
|
||||
expect(v.valid_value?('chocolate')).to eq(true)
|
||||
expect(v.valid_value?('chocolates')).to eq(false)
|
||||
|
||||
v = described_class.new(regex: '^[\w]+$')
|
||||
v.valid_value?('the_file').should == true
|
||||
v.valid_value?('the_file.bat').should == false
|
||||
expect(v.valid_value?('the_file')).to eq(true)
|
||||
expect(v.valid_value?('the_file.bat')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -40,12 +40,12 @@ describe StringSettingValidator do
|
|||
include_examples "for all StringSettingValidator opts"
|
||||
|
||||
it "returns true if length is ok" do
|
||||
validator.valid_value?('ok').should == true
|
||||
validator.valid_value?('yep long enough').should == true
|
||||
expect(validator.valid_value?('ok')).to eq(true)
|
||||
expect(validator.valid_value?('yep long enough')).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if too short" do
|
||||
validator.valid_value?('x').should == false
|
||||
expect(validator.valid_value?('x')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -55,43 +55,43 @@ describe StringSettingValidator do
|
|||
include_examples "for all StringSettingValidator opts"
|
||||
|
||||
it "returns true if length is ok" do
|
||||
validator.valid_value?('Z').should == true
|
||||
validator.valid_value?('abcde').should == true
|
||||
expect(validator.valid_value?('Z')).to eq(true)
|
||||
expect(validator.valid_value?('abcde')).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if too long" do
|
||||
validator.valid_value?('banana').should == false
|
||||
expect(validator.valid_value?('banana')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'combinations of options' do
|
||||
it "min and regex" do
|
||||
v = described_class.new(regex: '^[\w]+$', min: 3)
|
||||
v.valid_value?('chocolate').should == true
|
||||
v.valid_value?('hi').should == false
|
||||
v.valid_value?('game.exe').should == false
|
||||
expect(v.valid_value?('chocolate')).to eq(true)
|
||||
expect(v.valid_value?('hi')).to eq(false)
|
||||
expect(v.valid_value?('game.exe')).to eq(false)
|
||||
end
|
||||
|
||||
it "max and regex" do
|
||||
v = described_class.new(regex: '^[\w]+$', max: 5)
|
||||
v.valid_value?('chocolate').should == false
|
||||
v.valid_value?('a_b_c').should == true
|
||||
v.valid_value?('a b c').should == false
|
||||
expect(v.valid_value?('chocolate')).to eq(false)
|
||||
expect(v.valid_value?('a_b_c')).to eq(true)
|
||||
expect(v.valid_value?('a b c')).to eq(false)
|
||||
end
|
||||
|
||||
it "min and max" do
|
||||
v = described_class.new(min: 3, max: 5)
|
||||
v.valid_value?('chocolate').should == false
|
||||
v.valid_value?('a').should == false
|
||||
v.valid_value?('a b c').should == true
|
||||
v.valid_value?('a b').should == true
|
||||
expect(v.valid_value?('chocolate')).to eq(false)
|
||||
expect(v.valid_value?('a')).to eq(false)
|
||||
expect(v.valid_value?('a b c')).to eq(true)
|
||||
expect(v.valid_value?('a b')).to eq(true)
|
||||
end
|
||||
|
||||
it "min, max, and regex" do
|
||||
v = described_class.new(min: 3, max: 12, regex: 'bacon')
|
||||
v.valid_value?('go bacon!').should == true
|
||||
v.valid_value?('sprinkle bacon on your cereal').should == false
|
||||
v.valid_value?('ba').should == false
|
||||
expect(v.valid_value?('go bacon!')).to eq(true)
|
||||
expect(v.valid_value?('sprinkle bacon on your cereal')).to eq(false)
|
||||
expect(v.valid_value?('ba')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Reference in a new issue