spec/gnip-rule/rule_spec.rb in gnip-rule-0.3 vs spec/gnip-rule/rule_spec.rb in gnip-rule-0.3.1
- old
+ new
@@ -4,54 +4,55 @@
describe GnipRule::Rule do
describe '#initialize' do
it 'should allow an optional tag' do
rule = GnipRule::Rule.new('value')
- rule.tag.should == nil
+ rule.tag.should be_nil
rule_with_tag = GnipRule::Rule.new('value', 'tag')
rule_with_tag.tag.should == 'tag'
end
end
describe '#valid?' do
it 'should consider rules with "stop words" to be invalid' do
- rule = GnipRule::Rule.new('an value')
- rule.valid?.should == false
+ GnipRule::Rule.new('an value').should_not be_valid
end
it 'should consider rules that are too long to be invalid' do
rule = GnipRule::Rule.new('01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789')
- rule.valid?.should == false
+ rule.should_not be_valid
end
it 'should consider empty sources to be invalid' do
- rule = GnipRule::Rule.new('foo source: bar')
- rule.valid?.should == false
+ GnipRule::Rule.new('foo source: bar').should_not be_valid
end
it 'should consider negative ORs to be invalid' do
- rule = GnipRule::Rule.new('-iphone OR ipad')
- rule.valid?.should == false
+ GnipRule::Rule.new('-iphone OR ipad').should_not be_valid
end
it 'should consider rules with more than 10 positive terms invalid' do
- rule = GnipRule::Rule.new('one two three four five six seven eight nine ten eleven')
- rule.valid?.should == false
+ GnipRule::Rule.new('one two three four five six seven eight nine ten eleven').should_not be_valid
end
it 'should consider stop words within quotes to be valid' do
- rule = GnipRule::Rule.new('"foo the bar" baz')
- rule.valid?.should == true
+ GnipRule::Rule.new('"foo the bar" baz').should be_valid
end
it 'should consider rules without "stop words" to be valid' do
- rule = GnipRule::Rule.new('value')
- rule.valid?.should == true
+ GnipRule::Rule.new('value').should be_valid
end
end
- describe '#as_json' do
+ describe '#to_json' do
it 'should omit tag if tag not defined' do
rule = GnipRule::Rule.new('foo')
- rule.as_json.should == '{"value":"foo"}'
+ rule.to_json.should == '{"value":"foo"}'
end
it 'should add tag if defined' do
rule = GnipRule::Rule.new('foo', 'bar')
- rule.as_json.should == '{"value":"foo","tag":"bar"}'
+ rule.to_json.should == '{"value":"foo","tag":"bar"}'
+ end
+ end
+
+ describe '#to_rule' do
+ it 'should return itself' do
+ rule = GnipRule::Rule.new('foo', 'bar')
+ rule.to_rule.should == rule
end
end
end