i3ipc 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d1656014a13ed6678e5efba71d74c72e7d910906
4
- data.tar.gz: c41b56ab703cf2bc2322ed83218aa7f696e2552f
2
+ SHA256:
3
+ metadata.gz: 307a0123538855e09af5e01c6484533407be5bc08d8352d02c6073e439abb920
4
+ data.tar.gz: 18c8fe77d241cd6d357bb90b71e4dd68f50d6bcd01be3a8328861b037ca738b2
5
5
  SHA512:
6
- metadata.gz: 38f1d719f5c32f6ebd335d376481e76cb6be67ecba380af9753792654b05cf6adeecdb54847089fbf91372c3994291861d1cd49d22e9e660d3c62a9f1a3b5d69
7
- data.tar.gz: 136c448a42f39671740959c11c5beca1cd5f16115f2e983b590e6d60dbfd9ee480decde1f66b2c3fa4376ac708b5abe771fe055fd10f0ee2a676ba1adc2f045f
6
+ metadata.gz: 974bd5a6d1ec54be2d29807d7beb58b7d8bb65c518288efdc8a59470965a67157a8a5e463d62fe5bcf01b2d5c79ce096c1ae90291cff1908734b5335c8f56320
7
+ data.tar.gz: 94f3a38c802b40dea4f4f3e8e9164c108a714c3179ca8ebf51dfe3dfcc33c4d1641d148d512c0ec30398030318be322236124c80ac5198060eaa330f4bd96f69
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format documentation --color
data/Gemfile CHANGED
@@ -1,4 +1,9 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in i3ipc.gemspec
4
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rspec'
4
+
5
+ group :development do
6
+ gem 'guard'
7
+ gem 'guard-rspec'
8
+ gem 'pry'
9
+ end
@@ -0,0 +1,5 @@
1
+ guard :rspec, cmd: 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
@@ -27,9 +27,9 @@ module I3Ipc
27
27
  # con.close
28
28
  class Connection
29
29
 
30
- def initialize(connect = true)
31
- @protocol = Protocol.new
32
- open
30
+ def initialize(protocol = Protocol.new, autoconnect = true)
31
+ @protocol = protocol
32
+ open if autoconnect
33
33
  end
34
34
 
35
35
  def open
@@ -89,7 +89,7 @@ module I3Ipc
89
89
 
90
90
  private
91
91
 
92
- def reply_for(type, message = nil, events=nil)
92
+ def reply_for(type, message = nil)
93
93
  @protocol.send(type, message)
94
94
 
95
95
  Reply.parse(@protocol.receive type)
@@ -106,6 +106,5 @@ module I3Ipc
106
106
  else raise WrongEvent.new(event)
107
107
  end
108
108
  end
109
-
110
109
  end
111
110
  end
@@ -150,8 +150,15 @@ module I3Ipc
150
150
  end
151
151
 
152
152
  def get_socketpath
153
- path = `i3 --get-socketpath`.chomp!
154
- raise 'Unable to get i3 socketpath' unless path
153
+ cmd = if system('i3 --version')
154
+ 'i3'
155
+ elsif system('sway --version')
156
+ 'sway'
157
+ else
158
+ raise 'Unable to find i3 compatible window manager'
159
+ end
160
+ path = `#{cmd} --get-socketpath`.chomp!
161
+ raise 'Unable to get i3 compatible socketpath' unless path
155
162
  path
156
163
  end
157
164
 
@@ -45,7 +45,7 @@ module I3Ipc
45
45
  parse_data JSON.parse(response)
46
46
  end
47
47
 
48
- # Indicates whether this reply success or not.
48
+ # Indicates whether this reply is successful or not.
49
49
  #
50
50
  # @return false if this reply represents and error from i3-ipc protocol.
51
51
  # Otherwise returns true, which means that request is successful and
@@ -1,3 +1,3 @@
1
1
  module I3ipc
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -3,43 +3,81 @@ require 'spec_helper'
3
3
  module I3Ipc
4
4
  describe Connection do
5
5
 
6
+ let(:protocol) { Protocol.new '' }
7
+ let(:stub_protocol) do
8
+ allow(protocol).to receive(:send)
9
+ allow(protocol).to receive(:receive)
10
+ end
11
+ subject { Connection.new protocol, false }
12
+
6
13
  describe '#command' do
14
+ it 'returns i3ipc reply' do
15
+ stub_protocol.and_return('{}')
16
+ expect(subject.command('cmd')).to be_a Reply
17
+ end
7
18
 
8
- before(:all) do
9
- class Connection
10
- def initialize
11
- @protocol = Protocol.new ''
12
- end
13
- end
19
+ it 'sends correct command and receives success response' do
20
+ stub_protocol.and_return({ success: true }.to_json)
21
+ expect(subject.command('focus left').success?).to be true
14
22
  end
15
23
 
16
- it 'returns Reply object' do
17
- allow_any_instance_of(Protocol).to receive(:send)
18
- allow_any_instance_of(Protocol).to receive(:receive)
19
- .and_return("{}")
24
+ it 'sends incorrect command and receives error response' do
25
+ stub_protocol.and_return({ success: false, error: 'wrong command' }.to_json)
26
+ reply = subject.command('my command')
27
+ expect(reply.success).to be false
28
+ expect(reply.error).to eql 'wrong command'
29
+ end
30
+ end
20
31
 
21
- expect(Connection.new.command('cmd')).to be_a Reply
32
+ describe '#workspaces' do
33
+ it 'returns i3ipc reply' do
34
+ stub_protocol.and_return('{}')
35
+ expect(subject.workspaces).to be_a Reply
22
36
  end
37
+ end
23
38
 
24
- it 'sends correct command and receives success response' do
25
- allow_any_instance_of(Protocol).to receive(:send)
26
- allow_any_instance_of(Protocol).to receive(:receive)
27
- .and_return(%Q[{"success": true}])
39
+ describe '#outputs' do
40
+ it 'returns i3ipc reply' do
41
+ stub_protocol.and_return('{}')
42
+ expect(subject.outputs).to be_a Reply
43
+ end
44
+ end
28
45
 
29
- connection = Connection.new
30
- reply = connection.command('focus left')
31
- expect(reply.success).to be true
46
+ describe '#tree' do
47
+ it 'returns i3ipc reply' do
48
+ stub_protocol.and_return('{}')
49
+ expect(subject.tree).to be_a Reply
32
50
  end
51
+ end
33
52
 
34
- it 'sends incorrect command and receives error response' do
35
- allow_any_instance_of(Protocol).to receive(:send)
36
- allow_any_instance_of(Protocol).to receive(:receive)
37
- .and_return(%Q[{"success": false, "error": "wrong command"}])
53
+ describe '#marks' do
54
+ it 'returns i3ipc reply' do
55
+ stub_protocol.and_return('{}')
56
+ expect(subject.marks).to be_a Reply
57
+ end
58
+ end
38
59
 
39
- connection = Connection.new
40
- reply = connection.command('my command')
41
- expect(reply.success).to be false
42
- expect(reply.error).to eql 'wrong command'
60
+ describe '#bar_config' do
61
+ it 'returns i3ipc reply' do
62
+ stub_protocol.and_return('{}')
63
+ expect(subject.bar_config).to be_a Reply
64
+ end
65
+ end
66
+
67
+ describe '#version' do
68
+ it 'returns i3ipc reply' do
69
+ stub_protocol.and_return('{}')
70
+ expect(subject.version).to be_a Reply
71
+ end
72
+
73
+ it 'able to parse version attributes' do
74
+ resp = { human_readable: '4.2', minor: 2, patch: 0, major: 4 }
75
+ stub_protocol.and_return(resp.to_json)
76
+ reply = subject.version
77
+ expect(reply.human_readable).to eq resp[:human_readable]
78
+ expect(reply.minor).to eq resp[:minor]
79
+ expect(reply.patch).to eq resp[:patch]
80
+ expect(reply.major).to eq resp[:major]
43
81
  end
44
82
  end
45
83
  end
@@ -87,7 +87,7 @@ module I3Ipc
87
87
 
88
88
  it 'throws error if not connected' do
89
89
  subject.disconnect
90
- expect { subject.send(type) }.to raise_error
90
+ expect { subject.send(type) }.to raise_error Protocol::NotConnected
91
91
  end
92
92
  end
93
93
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i3ipc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitalii Elengaupt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-09 00:00:00.000000000 Z
11
+ date: 2019-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -64,9 +64,11 @@ extensions: []
64
64
  extra_rdoc_files: []
65
65
  files:
66
66
  - ".gitignore"
67
+ - ".rspec"
67
68
  - ".travis.yml"
68
69
  - ".yardopts"
69
70
  - Gemfile
71
+ - Guardfile
70
72
  - LICENSE.txt
71
73
  - README.md
72
74
  - Rakefile
@@ -101,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
103
  version: '0'
102
104
  requirements: []
103
105
  rubyforge_project:
104
- rubygems_version: 2.4.8
106
+ rubygems_version: 2.7.6
105
107
  signing_key:
106
108
  specification_version: 4
107
109
  summary: Interprocess communication with i3 wm
@@ -111,4 +113,3 @@ test_files:
111
113
  - spec/i3ipc/protocol_spec.rb
112
114
  - spec/i3ipc/reply_spec.rb
113
115
  - spec/spec_helper.rb
114
- has_rdoc: