spec/unit/rack/validation/param_spec.rb in goliath-1.0.4 vs spec/unit/rack/validation/param_spec.rb in goliath-1.0.5

- old
+ new

@@ -8,22 +8,22 @@ end it "should not allow invalid options" do lambda { Goliath::Rack::Validation::Param.new(@app, {:key => 'user', :as => Class.new}) - }.should raise_error + }.should raise_error(Exception) end it "raises if key is not supplied" do lambda { Goliath::Rack::Validation::Param.new(@app) }.should raise_error(Exception) end it "uses a default value if optional is not supplied" do cv = Goliath::Rack::Validation::Param.new(@app, :key => 'key') - cv.optional.should be_false + cv.optional.should be false end it "should have default and message be optional" do cv = nil lambda { @@ -38,11 +38,11 @@ it "should fail if given an invalid option" do cv = nil lambda { cv = Goliath::Rack::Validation::Param.new(@app, {:key => 'flag', :as => Goliath::Rack::Types::Boolean, :animal => :monkey}) - }.should raise_error + }.should raise_error('Unknown options: {:animal=>:monkey}') end context "fetch_key" do before do @cv = Goliath::Rack::Validation::Param.new(@app, @@ -125,56 +125,56 @@ body.should == app_body end context 'key_valid?' do it 'raises exception if the key is not provided' do - @rp.key_valid?(@env['params']).should be_false + @rp.key_valid?(@env['params']).should be false end it 'raises exception if the key is blank' do @env['params']['mk'] = '' - @rp.key_valid?(@env['params']).should be_false + @rp.key_valid?(@env['params']).should be false end it 'raises exception if the key is nil' do @env['params']['mk'] = nil - @rp.key_valid?(@env['params']).should be_false + @rp.key_valid?(@env['params']).should be false end it 'handles an empty array' do @env['params']['mk'] = [] - @rp.key_valid?(@env['params']).should be_false + @rp.key_valid?(@env['params']).should be false end it 'handles an array of nils' do @env['params']['mk'] = [nil, nil, nil] - @rp.key_valid?(@env['params']).should be_false + @rp.key_valid?(@env['params']).should be false end it 'handles an array of blanks' do @env['params']['mk'] = ['', '', ''] - @rp.key_valid?(@env['params']).should be_false + @rp.key_valid?(@env['params']).should be false end it "doesn't raise if the key provided" do @env['params']['mk'] = 'my value' - @rp.key_valid?(@env['params']).should be_true + @rp.key_valid?(@env['params']).should be true end it "doesn't raise if the array contains valid data" do @env['params']['mk'] = [1, 2, 3, 4] - @rp.key_valid?(@env['params']).should be_true + @rp.key_valid?(@env['params']).should be true end it "doesn't raise if the key provided is multiline and has blanks" do @env['params']['mk'] = "my\n \nvalue" - @rp.key_valid?(@env['params']).should be_true + @rp.key_valid?(@env['params']).should be true end it "doesn't raise if the key provided is an array and contains multiline with blanks" do @env['params']['mk'] = ["my\n \nvalue", "my\n \nother\n \nvalue"] - @rp.key_valid?(@env['params']).should be_true + @rp.key_valid?(@env['params']).should be true end end end context 'Nested keys tests' do @@ -192,22 +192,22 @@ 'login2' => "user", 'pass' => "password"} } } - @rp.key_valid?(@env['params']).should be_false + @rp.key_valid?(@env['params']).should be false end it "return true if key is present" do @env['params'] = {'data' => { 'credentials' => { 'login' => "user", 'pass' => "password"} } } - @rp.key_valid?(@env['params']).should be_true + @rp.key_valid?(@env['params']).should be true end end context 'Nested keys tests (with string)' do before do @@ -223,32 +223,32 @@ 'login2' => "user", 'pass' => "password"} } } - @rp.key_valid?(@env['params']).should be_false + @rp.key_valid?(@env['params']).should be false end it "return true if key is present" do @env['params'] = {'data' => { 'credentials' => { 'login' => "user", 'pass' => "password"} } } - @rp.key_valid?(@env['params']).should be_true + @rp.key_valid?(@env['params']).should be true end end end context "Coerce" do it "should only accept a class in the :as" do lambda { Goliath::Rack::Validation::Param.new(@app, {:key => 'user', :as => "not a class"}) - }.should raise_error + }.should raise_error('Params as must be a class') end context 'with middleware' do { Goliath::Rack::Types::Boolean => [['t', true], ['true', true], ['f', false],