ruby-osc 0.31.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Osc
2
- VERSION = "0.31.0"
3
+ VERSION = "1.0.0".freeze
3
4
  end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- $:.push File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
4
4
  require "ruby-osc/version"
5
5
 
6
6
  Gem::Specification.new do |s|
@@ -9,18 +9,16 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Macario"]
10
10
  s.email = ["macarui@gmail.com"]
11
11
  s.homepage = "http://makarius.me"
12
- s.summary = %q{Concise OSC Ruby implementation}
13
- s.description = %q{Concise OSC Ruby implementation}
12
+ s.summary = "Concise OSC Ruby implementation"
13
+ s.description = "Concise OSC Ruby implementation based on EventMachine"
14
+ s.licenses = ['MIT']
14
15
 
15
- s.rubyforge_project = "ruby-osc"
16
-
17
- s.add_development_dependency 'rspec', '>= 2.6.0'
18
- s.add_development_dependency 'bundler', '>= 1.0'
19
- s.add_dependency 'eventmachine', '>= 0.12.8'
16
+ s.add_development_dependency "rspec", "~> 3.8"
17
+ s.add_development_dependency "bundler", "~> 1.0"
18
+ s.add_dependency "eventmachine", "~> 1.2"
20
19
 
21
20
  s.files = `git ls-files`.split("\n")
22
21
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
22
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
23
  s.require_paths = ["lib"]
25
24
  end
26
-
@@ -1,96 +1,97 @@
1
+ # encoding: UTF-8
1
2
  require "#{ File.dirname __FILE__ }/spec_helper"
2
3
 
3
4
  describe Bundle do
4
5
  it "should accept bundle" do
5
- Bundle.new( Time.now, Bundle.new ).to_a.should == [Bundle.new]
6
+ expect(Bundle.new( Time.now, Bundle.new ).to_a).to eq([Bundle.new])
6
7
  end
7
8
 
8
9
  it "should accept message" do
9
- Bundle.new( Time.now, Message.new ).to_a.should == [Message.new]
10
+ expect(Bundle.new( Time.now, Message.new ).to_a).to eq([Message.new])
10
11
  end
11
12
 
12
13
  it "should rise TypeError if passing passing incorrect type" do
13
- lambda { Bundle.new Time.now, 1 }.should raise_error(TypeError)
14
+ expect { Bundle.new Time.now, 1 }.to raise_error(TypeError)
14
15
  end
15
-
16
+
16
17
  it "should raise TypeError if timetag is not Time" do
17
- lambda { Bundle.new 1 }.should raise_error(TypeError)
18
+ expect { Bundle.new 1 }.to raise_error(TypeError)
18
19
  end
19
-
20
+
20
21
  it "should accept nil for timetag" do
21
22
  Bundle.new nil
22
23
  end
23
24
 
24
- shared_examples_for 'Encodable Bundle' do
25
+ shared_examples_for "Encodable Bundle" do
25
26
  it "should encode" do
26
- @bundle.encode.should == @expected
27
+ expect(@bundle.encode).to eq(@expected)
27
28
  end
28
29
 
29
30
  it "should decode to bundle" do
30
- Bundle.decode(@expected).should be_a(Bundle)
31
+ expect(Bundle.decode(@expected)).to be_a(Bundle)
31
32
  end
32
33
 
33
34
  it "should decode timetag" do
34
- Bundle.decode(@expected).timetag.should == @bundle.timetag
35
+ expect(Bundle.decode(@expected).timetag).to eq(@bundle.timetag)
35
36
  end
36
37
 
37
38
  it "should actually decode" do
38
- Bundle.decode(@expected).should == @bundle
39
+ expect(Bundle.decode(@expected)).to eq(@bundle)
39
40
  end
40
41
  end
41
-
42
- describe 'Empty bundle nil timetag' do
42
+
43
+ describe "Empty bundle nil timetag" do
43
44
  before do
44
45
  @bundle = Bundle.new
45
- @expected = "#bundle\000\000\000\000\000\000\000\000\001"
46
+ @expected = "#bundle\000\000\000\000\000\000\000\000\001".force_encoding("binary")
46
47
  end
47
- it_should_behave_like 'Encodable Bundle'
48
+ it_should_behave_like "Encodable Bundle"
48
49
  end
49
-
50
- describe 'Empty bundle with timetag' do
50
+
51
+ describe "Empty bundle with timetag" do
51
52
  before do
52
- @bundle = Bundle.new Time.at(1251420949.16959)
53
- @expected = [35, 98, 117, 110, 100, 108, 101, 0, 206, 65, 169, 149, 43, 106, 64, 0].pack('C*')
53
+ @bundle = Bundle.new Time.at(1_251_420_949.16959)
54
+ @expected = [35, 98, 117, 110, 100, 108, 101, 0, 206, 65, 169, 149, 43, 106, 64, 0].pack("C*")
54
55
  end
55
- it_should_behave_like 'Encodable Bundle'
56
+ it_should_behave_like "Encodable Bundle"
56
57
  end
57
-
58
- describe 'Bundle with timetag and messages' do
58
+
59
+ describe "Bundle with timetag and messages" do
59
60
  before do
60
- @bundle = Bundle.new Time.at(946702800), Message.new('/bar/foo', 4, 3, 2, 1), Message.new('/foo/bar', 1, 2, 3, 4)
61
- @expected = [35, 98, 117, 110, 100, 108, 101, 0, 188, 24, 8, 80, 0, 0, 0, 0, 0, 0, 0, 36, 47, 98, 97, 114, 47, 102, 111, 111, 0, 0, 0, 0, 44, 105, 105, 105, 105, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 36, 47, 102, 111, 111, 47, 98, 97, 114, 0, 0, 0, 0, 44, 105, 105, 105, 105, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4].pack('C*')
61
+ @bundle = Bundle.new Time.at(946_702_800), Message.new("/bar/foo", 4, 3, 2, 1), Message.new("/foo/bar", 1, 2, 3, 4)
62
+ @expected = [35, 98, 117, 110, 100, 108, 101, 0, 188, 24, 8, 80, 0, 0, 0, 0, 0, 0, 0, 36, 47, 98, 97, 114, 47, 102, 111, 111, 0, 0, 0, 0, 44, 105, 105, 105, 105, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 36, 47, 102, 111, 111, 47, 98, 97, 114, 0, 0, 0, 0, 44, 105, 105, 105, 105, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4].pack("C*")
62
63
  end
63
- it_should_behave_like 'Encodable Bundle'
64
+ it_should_behave_like "Encodable Bundle"
64
65
  end
65
-
66
- describe 'Nested bundles' do
66
+
67
+ describe "Nested bundles" do
67
68
  before do
68
- @bundle = Bundle.new( nil, Bundle.new(nil, Message.new('/a')), Message.new('/b') )
69
- @expected = "#bundle\000\000\000\000\000\000\000\000\001\000\000\000\034#bundle\000\000\000\000\000\000\000\000\001\000\000\000\b/a\000\000,\000\000\000\000\000\000\b/b\000\000,\000\000\000"
69
+ @bundle = Bundle.new( nil, Bundle.new(nil, Message.new("/a")), Message.new("/b") )
70
+ @expected = "#bundle\000\000\000\000\000\000\000\000\001\000\000\000\034#bundle\000\000\000\000\000\000\000\000\001\000\000\000\b/a\000\000,\000\000\000\000\000\000\b/b\000\000,\000\000\000".force_encoding("binary")
70
71
  end
71
- it_should_behave_like 'Encodable Bundle'
72
+ it_should_behave_like "Encodable Bundle"
72
73
  end
73
-
74
- describe 'Complex blob' do
74
+
75
+ describe "Complex blob" do
75
76
  before do
76
- data = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 4, 104, 111, 108, 97, 0, 2, 67, -36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 0, 0 ].pack('C*')
77
- @bundle = Bundle.new nil, Message.new('/d_recv', Blob.new(data), 0)
78
- @expected = [35, 98, 117, 110, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 76, 47, 100, 95, 114, 101, 99, 118, 0, 44, 98, 105, 0, 0, 0, 0, 56, 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 4, 104, 111, 108, 97, 0, 2, 67, 220, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, 255, 255, 0, 0, 255, 255, 0, 1, 2, 0, 0, 0, 0, 0, 0].pack('C*')
77
+ data = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 4, 104, 111, 108, 97, 0, 2, 67, -36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 0, 0 ].pack("C*")
78
+ @bundle = Bundle.new nil, Message.new("/d_recv", Blob.new(data), 0)
79
+ @expected = [35, 98, 117, 110, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 76, 47, 100, 95, 114, 101, 99, 118, 0, 44, 98, 105, 0, 0, 0, 0, 56, 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 4, 104, 111, 108, 97, 0, 2, 67, 220, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, 255, 255, 0, 0, 255, 255, 0, 1, 2, 0, 0, 0, 0, 0, 0].pack("C*")
79
80
  end
80
- it_should_behave_like 'Encodable Bundle'
81
+ it_should_behave_like "Encodable Bundle"
81
82
  end
82
-
83
- describe 'Complex blob 2' do
83
+
84
+ describe "Complex blob 2" do
84
85
  before do
85
- data = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 2, 97, 109, 0, 7, 0, 0, 0, 0, 63, 0, 0, 0, 63, -128, 0, 0, 64, 0, 0, 0, -62, -58, 0, 0, 64, -96, 0, 0, -64, -128, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 103, 97, 116, 101, 0, 0, 9, 112, 111, 114, 116, 97, 100, 111, 114, 97, 0, 1, 10, 109, 111, 100, 117, 108, 97, 100, 111, 114, 97, 0, 2, 3, 97, 109, 112, 0, 3, 0, 8, 7, 67, 111, 110, 116, 114, 111, 108, 1, 0, 0, 0, 4, 0, 0, 1, 1, 1, 1, 6, 83, 105, 110, 79, 115, 99, 1, 0, 2, 0, 1, 0, 0, 0, 0, 0, 2, -1, -1, 0, 0, 1, 6, 77, 117, 108, 65, 100, 100, 1, 0, 3, 0, 1, 0, 0, 0, 1, 0, 0, -1, -1, 0, 1, -1, -1, 0, 1, 1, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, 0, 0, 0, 1, -1, -1, 0, 0, 2, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 3, 0, 0, 0, 2, 0, 0, 2, 6, 69, 110, 118, 71, 101, 110, 1, 0, 17, 0, 1, 0, 0, 0, 0, 0, 0, -1, -1, 0, 2, -1, -1, 0, 0, -1, -1, 0, 2, -1, -1, 0, 3, -1, -1, 0, 0, -1, -1, 0, 3, -1, -1, 0, 2, -1, -1, 0, 4, -1, -1, 0, 2, -1, -1, 0, 3, -1, -1, 0, 5, -1, -1, 0, 6, -1, -1, 0, 0, -1, -1, 0, 3, -1, -1, 0, 5, -1, -1, 0, 6, 1, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 4, 0, 0, 0, 5, 0, 0, 2, 3, 79, 117, 116, 2, 0, 2, 0, 0, 0, 0, -1, -1, 0, 0, 0, 6, 0, 0, 0, 0 ].pack('C*')
86
- @bundle = Bundle.new nil, Message.new('/d_recv', Blob.new(data), 0)
87
- @expected = [35, 98, 117, 110, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 124, 47, 100, 95, 114, 101, 99, 118, 0, 44, 98, 105, 0, 0, 0, 1, 101, 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 2, 97, 109, 0, 7, 0, 0, 0, 0, 63, 0, 0, 0, 63, 128, 0, 0, 64, 0, 0, 0, 194, 198, 0, 0, 64, 160, 0, 0, 192, 128, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 103, 97, 116, 101, 0, 0, 9, 112, 111, 114, 116, 97, 100, 111, 114, 97, 0, 1, 10, 109, 111, 100, 117, 108, 97, 100, 111, 114, 97, 0, 2, 3, 97, 109, 112, 0, 3, 0, 8, 7, 67, 111, 110, 116, 114, 111, 108, 1, 0, 0, 0, 4, 0, 0, 1, 1, 1, 1, 6, 83, 105, 110, 79, 115, 99, 1, 0, 2, 0, 1, 0, 0, 0, 0, 0, 2, 255, 255, 0, 0, 1, 6, 77, 117, 108, 65, 100, 100, 1, 0, 3, 0, 1, 0, 0, 0, 1, 0, 0, 255, 255, 0, 1, 255, 255, 0, 1, 1, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, 0, 0, 0, 1, 255, 255, 0, 0, 2, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 3, 0, 0, 0, 2, 0, 0, 2, 6, 69, 110, 118, 71, 101, 110, 1, 0, 17, 0, 1, 0, 0, 0, 0, 0, 0, 255, 255, 0, 2, 255, 255, 0, 0, 255, 255, 0, 2, 255, 255, 0, 3, 255, 255, 0, 0, 255, 255, 0, 3, 255, 255, 0, 2, 255, 255, 0, 4, 255, 255, 0, 2, 255, 255, 0, 3, 255, 255, 0, 5, 255, 255, 0, 6, 255, 255, 0, 0, 255, 255, 0, 3, 255, 255, 0, 5, 255, 255, 0, 6, 1, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 4, 0, 0, 0, 5, 0, 0, 2, 3, 79, 117, 116, 2, 0, 2, 0, 0, 0, 0, 255, 255, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].pack('C*')
88
- end
89
- it_should_behave_like 'Encodable Bundle'
86
+ data = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 2, 97, 109, 0, 7, 0, 0, 0, 0, 63, 0, 0, 0, 63, -128, 0, 0, 64, 0, 0, 0, -62, -58, 0, 0, 64, -96, 0, 0, -64, -128, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 103, 97, 116, 101, 0, 0, 9, 112, 111, 114, 116, 97, 100, 111, 114, 97, 0, 1, 10, 109, 111, 100, 117, 108, 97, 100, 111, 114, 97, 0, 2, 3, 97, 109, 112, 0, 3, 0, 8, 7, 67, 111, 110, 116, 114, 111, 108, 1, 0, 0, 0, 4, 0, 0, 1, 1, 1, 1, 6, 83, 105, 110, 79, 115, 99, 1, 0, 2, 0, 1, 0, 0, 0, 0, 0, 2, -1, -1, 0, 0, 1, 6, 77, 117, 108, 65, 100, 100, 1, 0, 3, 0, 1, 0, 0, 0, 1, 0, 0, -1, -1, 0, 1, -1, -1, 0, 1, 1, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, 0, 0, 0, 1, -1, -1, 0, 0, 2, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 3, 0, 0, 0, 2, 0, 0, 2, 6, 69, 110, 118, 71, 101, 110, 1, 0, 17, 0, 1, 0, 0, 0, 0, 0, 0, -1, -1, 0, 2, -1, -1, 0, 0, -1, -1, 0, 2, -1, -1, 0, 3, -1, -1, 0, 0, -1, -1, 0, 3, -1, -1, 0, 2, -1, -1, 0, 4, -1, -1, 0, 2, -1, -1, 0, 3, -1, -1, 0, 5, -1, -1, 0, 6, -1, -1, 0, 0, -1, -1, 0, 3, -1, -1, 0, 5, -1, -1, 0, 6, 1, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 4, 0, 0, 0, 5, 0, 0, 2, 3, 79, 117, 116, 2, 0, 2, 0, 0, 0, 0, -1, -1, 0, 0, 0, 6, 0, 0, 0, 0 ].pack("C*")
87
+ @bundle = Bundle.new nil, Message.new("/d_recv", Blob.new(data), 0)
88
+ @expected = [35, 98, 117, 110, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 124, 47, 100, 95, 114, 101, 99, 118, 0, 44, 98, 105, 0, 0, 0, 1, 101, 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 2, 97, 109, 0, 7, 0, 0, 0, 0, 63, 0, 0, 0, 63, 128, 0, 0, 64, 0, 0, 0, 194, 198, 0, 0, 64, 160, 0, 0, 192, 128, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 103, 97, 116, 101, 0, 0, 9, 112, 111, 114, 116, 97, 100, 111, 114, 97, 0, 1, 10, 109, 111, 100, 117, 108, 97, 100, 111, 114, 97, 0, 2, 3, 97, 109, 112, 0, 3, 0, 8, 7, 67, 111, 110, 116, 114, 111, 108, 1, 0, 0, 0, 4, 0, 0, 1, 1, 1, 1, 6, 83, 105, 110, 79, 115, 99, 1, 0, 2, 0, 1, 0, 0, 0, 0, 0, 2, 255, 255, 0, 0, 1, 6, 77, 117, 108, 65, 100, 100, 1, 0, 3, 0, 1, 0, 0, 0, 1, 0, 0, 255, 255, 0, 1, 255, 255, 0, 1, 1, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, 0, 0, 0, 1, 255, 255, 0, 0, 2, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 3, 0, 0, 0, 2, 0, 0, 2, 6, 69, 110, 118, 71, 101, 110, 1, 0, 17, 0, 1, 0, 0, 0, 0, 0, 0, 255, 255, 0, 2, 255, 255, 0, 0, 255, 255, 0, 2, 255, 255, 0, 3, 255, 255, 0, 0, 255, 255, 0, 3, 255, 255, 0, 2, 255, 255, 0, 4, 255, 255, 0, 2, 255, 255, 0, 3, 255, 255, 0, 5, 255, 255, 0, 6, 255, 255, 0, 0, 255, 255, 0, 3, 255, 255, 0, 5, 255, 255, 0, 6, 1, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 4, 0, 0, 0, 5, 0, 0, 2, 3, 79, 117, 116, 2, 0, 2, 0, 0, 0, 0, 255, 255, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].pack("C*")
89
+ end
90
+ it_should_behave_like "Encodable Bundle"
90
91
  end
91
-
92
- it 'Should raise OSC::DecodeError with bad encoded bundle' do
93
- bad_data = "#bundle\000\000\000\000\000\000\000\000\001\000\000\000\034#bundle\000\000\000\000\000\001\000\000\000\b/a\000\000,\000\000\000\000\000\000\b/b\000\000,\000\000\000"
94
- lambda { Bundle.decode bad_data }.should raise_error(DecodeError)
92
+
93
+ it "Should raise OSC::DecodeError with bad encoded bundle" do
94
+ bad_data = "#bundle\000\000\000\000\000\000\000\000\001\000\000\000\034#bundle\000\000\000\000\000\001\000\000\000\b/a\000\000,\000\000\000\000\000\000\b/b\000\000,\000\000\000".force_encoding("binary")
95
+ expect { Bundle.decode bad_data }.to raise_error(DecodeError)
95
96
  end
96
97
  end
@@ -1,164 +1,207 @@
1
+ # encoding: utf-8
1
2
  require "#{ File.dirname __FILE__ }/spec_helper"
2
3
 
3
4
  describe Message do
4
-
5
5
  it "should raise TypeError if passing wrong type" do
6
- lambda { Message.new('address', Class) }.should raise_error(TypeError)
6
+ expect { Message.new("address", Class) }.to raise_error(TypeError)
7
7
  end
8
-
8
+
9
9
  it "should raise TypeError if not passing a string for address" do
10
- lambda { Message.new(OSC) }.should raise_error(TypeError)
10
+ expect { Message.new(OSC) }.to raise_error(TypeError)
11
11
  end
12
-
12
+
13
13
  it "should have address" do
14
- Message.new('/foo/bar').address.should == '/foo/bar'
14
+ expect(Message.new("/foo/bar").address).to eq("/foo/bar")
15
+ end
16
+
17
+ it "should accept utf8 address" do
18
+ expect(Message.new("/foo/bär").address).to eq("/foo/bär")
15
19
  end
16
-
20
+
17
21
  it "should collect args" do
18
- Message.new('/foo/bar', 1, 2, 3, 4).args.size.should == 4
22
+ expect(Message.new("/foo/bar", 1, 2, 3, 4).args.size).to eq(4)
19
23
  end
20
-
24
+
21
25
  it "should accept integer" do
22
- Message.new('/foo/bar', 1).args.should == [1]
26
+ expect(Message.new("/foo/bar", 1).args).to eq([1])
23
27
  end
24
-
28
+
25
29
  it "should should accept float" do
26
- Message.new('/foo/bar', 1.0).args.should == [1.0]
30
+ expect(Message.new("/foo/bar", 1.0).args).to eq([1.0])
27
31
  end
28
-
32
+
29
33
  it "should accept string" do
30
- Message.new('/foo/bar', 'string').args.should == ['string']
34
+ expect(Message.new("/foo/bar", "string").args).to eq(["string"])
31
35
  end
32
-
36
+
33
37
  it "should accept Blob" do
34
- Message.new('/foo/bar', Blob.new('blob')).args.should == [Blob.new('blob')]
38
+ expect(Message.new("/foo/bar", Blob.new("blob")).args).to eq([Blob.new("blob")])
35
39
  end
36
-
40
+
37
41
  it "should convert to array" do
38
- Message.new('/foo/bar', 1, 2, 3, 4).to_a.should == ['/foo/bar', 1, 2, 3, 4]
42
+ expect(Message.new("/foo/bar", 1, 2, 3, 4).to_a).to eq(["/foo/bar", 1, 2, 3, 4])
39
43
  end
40
-
41
- describe 'Custom argument coercion' do
42
-
44
+
45
+ describe "Custom argument coercion" do
43
46
  before do
44
47
  TrueClass.send(:include, OSCArgument)
45
48
  TrueClass.send( :define_method, :to_osc_type){ 1 }
46
49
  FalseClass.send(:include, OSCArgument)
47
50
  FalseClass.send( :define_method, :to_osc_type){ 0 }
48
51
  Hash.send(:include, OSCArgument)
49
- Hash.send( :define_method, :to_osc_type) do
50
- self.to_a.collect{ |pair| pair.collect{ |a| OSC.coerce_argument a } }
52
+ Hash.send( :define_method, :to_osc_type) do
53
+ to_a.collect{ |pair| pair.collect{ |a| OSC.coerce_argument a } }
51
54
  end
52
55
  end
53
-
56
+
54
57
  it "should accept true" do
55
- Message.new('/foo/bar', true).args.should == [1]
58
+ expect(Message.new("/foo/bar", true).args).to eq([1])
56
59
  end
57
60
 
58
61
  it "should accept false" do
59
- Message.new('/foo/bar', false).args.should == [0]
62
+ expect(Message.new("/foo/bar", false).args).to eq([0])
60
63
  end
61
64
 
62
65
  it "should accept hash" do
63
- Message.new('/foo/bar', {:a => :b}).args.should == ["a", "b"]
66
+ expect(Message.new("/foo/bar", a: :b).args).to eq(%w(a b))
64
67
  end
65
68
  end
66
-
67
- describe 'Encode/decode' do
68
- shared_examples_for 'Encodable Message' do
69
+
70
+ describe "Encode/decode" do
71
+ shared_examples_for "Encodable Message" do
69
72
  it "should encode" do
70
- @message.encode.should == @expected
73
+ expect(@message.encode).to eq(@expected)
71
74
  end
72
-
75
+
73
76
  it "should decode to message" do
74
- Message.decode(@expected).should be_a(Message)
77
+ expect(Message.decode(@expected)).to be_a(Message)
75
78
  end
76
-
79
+
77
80
  it "should decode address" do
78
- Message.decode(@expected).address.should == @message.address
81
+ expect(Message.decode(@expected).address).to eq(@message.address)
79
82
  end
80
-
83
+
81
84
  it "should actually decode" do
82
- Message.decode(@expected).to_a.inspect.should == @message.to_a.inspect.to_s # Problem with float comparing
85
+ expect(Message.decode(@expected)).to eq(@message)
83
86
  end
84
87
  end
85
-
86
- describe 'Address' do
88
+
89
+ describe "Address" do
87
90
  before do
88
- @message = Message.new('/foo/bar/long/very/long/long/long/address')
89
- @expected = "/foo/bar/long/very/long/long/long/address\000\000\000,\000\000\000"
91
+ @message = Message.new("/foo/bar/long/very/long/long/long/address")
92
+ @expected = "/foo/bar/long/very/long/long/long/address\000\000\000,\000\000\000".force_encoding("binary")
90
93
  end
91
- it_should_behave_like 'Encodable Message'
94
+ it_should_behave_like "Encodable Message"
92
95
  end
93
-
94
- describe 'Integer' do
96
+
97
+ describe "Integer" do
95
98
  before do
96
- @message = Message.new('/foo/barz', 2)
97
- @expected = "/foo/barz\000\000\000,i\000\000\000\000\000\002"
99
+ @message = Message.new("/foo/barz", 2)
100
+ @expected = "/foo/barz\000\000\000,i\000\000\000\000\000\002".force_encoding("binary")
98
101
  end
99
- it_should_behave_like 'Encodable Message'
102
+ it_should_behave_like "Encodable Message"
100
103
  end
101
-
102
- describe 'Negative Integer' do
104
+
105
+ describe "Negative Integer" do
103
106
  before do
104
- @message = Message.new('/foo/barz', -2)
105
- @expected = "/foo/barz\000\000\000,i\000\000\377\377\377\376"
107
+ @message = Message.new("/foo/barz", -2)
108
+ @expected = "/foo/barz\000\000\000,i\000\000\377\377\377\376".force_encoding("binary")
106
109
  end
107
- it_should_behave_like 'Encodable Message'
110
+ it_should_behave_like "Encodable Message"
108
111
  end
109
-
110
- describe 'Float' do
112
+
113
+ describe "Float" do
111
114
  before do
112
- @message = Message.new('/foo/bar', 1.100000023841858)
113
- @expected = [47, 102, 111, 111, 47, 98, 97, 114, 0, 0, 0, 0, 44, 102, 0, 0, 63, 140, 204, 205].pack('C*')
115
+ @message = Message.new("/foo/bar", 1.100000023841858)
116
+ @expected = [47, 102, 111, 111, 47, 98, 97, 114, 0, 0, 0, 0, 44, 102, 0, 0, 63, 140, 204, 205].pack("C*")
114
117
  end
115
- it_should_behave_like 'Encodable Message'
118
+ it_should_behave_like "Encodable Message"
116
119
  end
117
-
118
- describe 'Negative Float' do
120
+
121
+ describe "Negative Float" do
119
122
  before do
120
- @message = Message.new('/foo/bar', -1.100000023841858)
121
- @expected = [47, 102, 111, 111, 47, 98, 97, 114, 0, 0, 0, 0, 44, 102, 0, 0, 191, 140, 204, 205].pack('C*')
123
+ @message = Message.new("/foo/bar", -1.100000023841858)
124
+ @expected = [47, 102, 111, 111, 47, 98, 97, 114, 0, 0, 0, 0, 44, 102, 0, 0, 191, 140, 204, 205].pack("C*")
122
125
  end
123
- it_should_behave_like 'Encodable Message'
126
+ it_should_behave_like "Encodable Message"
124
127
  end
125
-
126
- describe 'String' do
128
+
129
+ describe "Double" do
127
130
  before do
128
- @message = Message.new('/foo/bar', 'a string to encode')
129
- @expected = "/foo/bar\000\000\000\000,s\000\000a string to encode\000\000"
131
+ @message = Message.new("/foo/bar", 1.100000023841858)
132
+
133
+ @expected = [
134
+ 47, 102, 111, 111, 47, 98, 97, 114, 0, 0, 0, 0, 44, 100,
135
+ 0, 0, 63, 241, 153, 153, 160, 0, 0, 0
136
+ ].pack("C*")
137
+ end
138
+
139
+ it "should decode to message" do
140
+ expect(Message.decode(@expected)).to be_a(Message)
141
+ end
142
+
143
+ it "should decode address" do
144
+ expect(Message.decode(@expected).address)
145
+ .to eq(@message.address)
146
+ end
147
+
148
+ it "should actually decode" do
149
+ expect(Message.decode(@expected)).to eq(@message)
130
150
  end
131
- it_should_behave_like 'Encodable Message'
132
151
  end
133
152
 
134
- describe 'Multiple types' do
153
+ describe "String" do
135
154
  before do
136
- @message = Message.new('/foo/barzzz', 2, 1.440000057220459, 'basho')
137
- @expected = [47, 102, 111, 111, 47, 98, 97, 114, 122, 122, 122, 0, 44, 105, 102, 115, 0, 0, 0, 0, 0, 0, 0, 2, 63, 184, 81, 236, 98, 97, 115, 104, 111, 0, 0, 0].pack('C*')
155
+ @message = Message.new("/foo/bar", "a string to encode")
156
+ @expected = "/foo/bar\000\000\000\000,s\000\000a string to encode\000\000".force_encoding("binary")
138
157
  end
139
- it_should_behave_like 'Encodable Message'
158
+ it_should_behave_like "Encodable Message"
140
159
  end
141
-
142
- describe 'Blob' do
160
+
161
+ describe "UTF8 String" do
143
162
  before do
144
- @message = Message.new('/foo/bar', Blob.new('test blob'))
145
- @expected = "/foo/bar\000\000\000\000,b\000\000\000\000\000\ttest blob\000\000\000"
163
+ @message = Message.new("/foo/bar", "a string to äncode")
164
+ @expected = "/foo/bar\000\000\000\000,s\000\000a string to äncode\000".force_encoding("binary")
146
165
  end
147
- it_should_behave_like 'Encodable Message'
148
-
166
+ it_should_behave_like "Encodable Message"
167
+ end
168
+
169
+ describe "Multiple types" do
170
+ before do
171
+ @message = Message.new("/foo/barzzz", 2, 1.440000057220459, "basho")
172
+ @expected = [47, 102, 111, 111, 47, 98, 97, 114, 122, 122, 122, 0, 44, 105, 102, 115, 0, 0, 0, 0, 0, 0, 0, 2, 63, 184, 81, 236, 98, 97, 115, 104, 111, 0, 0, 0].pack("C*")
173
+ end
174
+ it_should_behave_like "Encodable Message"
175
+ end
176
+
177
+ describe "Blob" do
178
+ before do
179
+ @message = Message.new("/foo/bar", Blob.new("test blob"))
180
+ @expected = "/foo/bar\000\000\000\000,b\000\000\000\000\000\ttest blob\000\000\000".force_encoding("binary")
181
+ end
182
+ it_should_behave_like "Encodable Message"
183
+
149
184
  it "should raise if size doesn't correspond and return empty message" do
150
- lambda do
151
- Message.decode("/foo/bar\000\000\000\000,b\000\000\000\000\000\020test blob\000\000\000")
152
- end.should raise_error
185
+ expect do
186
+ Message.decode("/foo/bar\000\000\000\000,b\000\000\000\000\000\020test blob\000\000\000".force_encoding("binary"))
187
+ end.to raise_error(OSC::DecodeError)
153
188
  end
154
189
  end
155
-
156
- describe 'Lots of ints' do
190
+
191
+ describe "Lots of ints" do
157
192
  before do
158
- @message = Message.new('/bar/foo', 4, 3, 2, 1)
159
- @expected = "/bar/foo\000\000\000\000,iiii\000\000\000\000\000\000\004\000\000\000\003\000\000\000\002\000\000\000\001"
193
+ @message = Message.new("/bar/foo", 4, 3, 2, 1)
194
+ @expected = "/bar/foo\000\000\000\000,iiii\000\000\000\000\000\000\004\000\000\000\003\000\000\000\002\000\000\000\001".force_encoding("binary")
160
195
  end
161
- it_should_behave_like 'Encodable Message'
196
+ it_should_behave_like "Encodable Message"
162
197
  end
163
- end
198
+
199
+ describe "Invalid message" do
200
+ it "should raise if invalid tag is used" do
201
+ expect do
202
+ Message.decode("/foo/bar\000\000\000\000,k\000\000\000\000\000\020test blob\000\000\000".force_encoding("binary"))
203
+ end.to raise_exception(DecodeError)
204
+ end
205
+ end
206
+ end
164
207
  end