spec/blather/stanza/presence/status_spec.rb in blather-0.6.2 vs spec/blather/stanza/presence/status_spec.rb in blather-0.7.0
- old
+ new
@@ -1,93 +1,105 @@
require 'spec_helper'
describe Blather::Stanza::Presence::Status do
it 'registers itself' do
- Blather::XMPPNode.class_from_registration(:status, nil).must_equal Blather::Stanza::Presence::Status
+ Blather::XMPPNode.class_from_registration(:status, nil).should == Blather::Stanza::Presence::Status
end
it 'must be importable as unavailable' do
- doc = parse_stanza '<presence type="unavailable"/>'
- Blather::XMPPNode.import(doc.root).must_be_instance_of Blather::Stanza::Presence::Status
+ Blather::XMPPNode.parse('<presence type="unavailable"/>').should be_kind_of Blather::Stanza::Presence::Status::InstanceMethods
end
it 'must be importable as nil' do
- doc = parse_stanza '<presence/>'
- Blather::XMPPNode.import(doc.root).must_be_instance_of Blather::Stanza::Presence::Status
+ Blather::XMPPNode.parse('<presence/>').should be_kind_of Blather::Stanza::Presence::Status::InstanceMethods
end
+ it 'must be importable with show, status and priority children' do
+ n = Blather::XMPPNode.parse <<-XML
+ <presence from='bard@shakespeare.lit/globe'>
+ <show>chat</show>
+ <status>Talk to me!</status>
+ <priority>10</priority>
+ </presence>
+ XML
+ n.should be_kind_of Blather::Stanza::Presence::Status::InstanceMethods
+ n.state.should == :chat
+ n.message.should == 'Talk to me!'
+ n.priority.should == 10
+ end
+
it 'can set state on creation' do
status = Blather::Stanza::Presence::Status.new :away
- status.state.must_equal :away
+ status.state.should == :away
end
it 'can set a message on creation' do
status = Blather::Stanza::Presence::Status.new nil, 'Say hello!'
- status.message.must_equal 'Say hello!'
+ status.message.should == 'Say hello!'
end
it 'ensures type is nil or :unavailable' do
status = Blather::Stanza::Presence::Status.new
- lambda { status.type = :invalid_type_name }.must_raise(Blather::ArgumentError)
+ lambda { status.type = :invalid_type_name }.should raise_error(Blather::ArgumentError)
[nil, :unavailable].each do |valid_type|
status.type = valid_type
- status.type.must_equal valid_type
+ status.type.should == valid_type
end
end
it 'ensures state is one of Presence::Status::VALID_STATES' do
status = Blather::Stanza::Presence::Status.new
- lambda { status.state = :invalid_type_name }.must_raise(Blather::ArgumentError)
+ lambda { status.state = :invalid_type_name }.should raise_error(Blather::ArgumentError)
Blather::Stanza::Presence::Status::VALID_STATES.each do |valid_state|
status.state = valid_state
- status.state.must_equal valid_state
+ status.state.should == valid_state
end
end
it 'returns :available if state is nil' do
- Blather::Stanza::Presence::Status.new.state.must_equal :available
+ Blather::Stanza::Presence::Status.new.state.should == :available
end
it 'returns :available if <show/> is blank' do
- status = Blather::XMPPNode.import(parse_stanza(<<-NODE).root)
+ status = Blather::XMPPNode.parse(<<-NODE)
<presence><show/></presence>
NODE
- status.state.must_equal :available
+ status.state.should == :available
end
it 'returns :unavailable if type is :unavailable' do
status = Blather::Stanza::Presence::Status.new
status.type = :unavailable
- status.state.must_equal :unavailable
+ status.state.should == :unavailable
end
it 'ensures priority is not greater than 127' do
- lambda { Blather::Stanza::Presence::Status.new.priority = 128 }.must_raise(Blather::ArgumentError)
+ lambda { Blather::Stanza::Presence::Status.new.priority = 128 }.should raise_error(Blather::ArgumentError)
end
it 'ensures priority is not less than -128' do
- lambda { Blather::Stanza::Presence::Status.new.priority = -129 }.must_raise(Blather::ArgumentError)
+ lambda { Blather::Stanza::Presence::Status.new.priority = -129 }.should raise_error(Blather::ArgumentError)
end
it 'has "attr_accessor" for priority' do
status = Blather::Stanza::Presence::Status.new
- status.priority.must_equal 0
+ status.priority.should == 0
status.priority = 10
- status.children.detect { |n| n.element_name == 'priority' }.wont_be_nil
- status.priority.must_equal 10
+ status.children.detect { |n| n.element_name == 'priority' }.should_not be_nil
+ status.priority.should == 10
end
it 'has "attr_accessor" for message' do
status = Blather::Stanza::Presence::Status.new
- status.message.must_be_nil
+ status.message.should be_nil
status.message = 'new message'
- status.children.detect { |n| n.element_name == 'status' }.wont_be_nil
- status.message.must_equal 'new message'
+ status.children.detect { |n| n.element_name == 'status' }.should_not be_nil
+ status.message.should == 'new message'
end
it 'must be comparable by priority' do
jid = Blather::JID.new 'a@b/c'
@@ -97,36 +109,36 @@
status2 = Blather::Stanza::Presence::Status.new
status2.from = jid
status1.priority = 1
status2.priority = -1
- (status1 <=> status2).must_equal 1
- (status2 <=> status1).must_equal -1
+ (status1 <=> status2).should == 1
+ (status2 <=> status1).should == -1
status2.priority = 1
- (status1 <=> status2).must_equal 0
+ (status1 <=> status2).should == 0
end
it 'raises an argument error if compared to a status with a different Blather::JID' do
status1 = Blather::Stanza::Presence::Status.new
status1.from = 'a@b/c'
status2 = Blather::Stanza::Presence::Status.new
status2.from = 'd@e/f'
- lambda { status1 <=> status2 }.must_raise(Blather::ArgumentError)
+ lambda { status1 <=> status2 }.should raise_error(Blather::ArgumentError)
end
([:available] + Blather::Stanza::Presence::Status::VALID_STATES).each do |valid_state|
it "provides a helper (#{valid_state}?) for state #{valid_state}" do
- Blather::Stanza::Presence::Status.new.must_respond_to :"#{valid_state}?"
+ Blather::Stanza::Presence::Status.new.should respond_to :"#{valid_state}?"
end
it "returns true on call to (#{valid_state}?) if state == #{valid_state}" do
method = "#{valid_state}?".to_sym
stat = Blather::Stanza::Presence::Status.new
stat.state = valid_state
- stat.must_respond_to method
- stat.__send__(method).must_equal true
+ stat.should respond_to method
+ stat.__send__(method).should == true
end
end
end