gas 0.1.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,82 @@
1
+ require './spec/spec_helper'
2
+
3
+ require './lib/gas'
4
+
5
+ describe Gas::GitConfig do
6
+
7
+ before :each do
8
+ @name = 'Fredrik Wallgren'
9
+ @email = 'fredrik.wallgren@gmail.com'
10
+ @nickname = 'Fred'
11
+ end
12
+
13
+ it 'should be able to get current user from gitconfig' do
14
+ mock_cli_call(Gas::GitConfig, 'git config --global --get user.name') { @name + "\n" }
15
+ mock_cli_call(Gas::GitConfig, 'git config --global --get user.email') { @email + "\n" }
16
+
17
+ user = Gas::GitConfig.current_user
18
+ user.name.should eq @name
19
+ user.email.should eq @email
20
+ end
21
+
22
+ it 'should return nil if no current user is present in gitconfig' do
23
+ mock_cli_call(Gas::GitConfig, 'git config --global --get user.name') { nil }
24
+ mock_cli_call(Gas::GitConfig, 'git config --global --get user.email') { nil }
25
+
26
+ Gas::GitConfig.current_user.should be_nil
27
+ end
28
+
29
+
30
+ describe "Multiple users" do
31
+
32
+ before :each do
33
+ @user1 = Gas::User.new(@name, @email, @nickname) # create a primary user for testing
34
+ end
35
+
36
+ it "should be able to set the current user" do
37
+ # setup the cli interrupt things...
38
+ mock_cli_call(Gas::GitConfig, "git config --global user.name \"#{@user1.name}\"") { nil }
39
+ mock_cli_call(Gas::GitConfig, "git config --global user.email \"#{@user1.email}\"") { nil }
40
+ mock_cli_call(Gas::GitConfig, 'git config --global --get user.name') { @user1.name + "\n" }
41
+ mock_cli_call(Gas::GitConfig, 'git config --global --get user.email') { @user1.email + "\n" }
42
+
43
+ Gas::GitConfig.change_user @user1
44
+
45
+ user = Gas::GitConfig.current_user
46
+ user.name.should eq @user1.name
47
+ user.email.should eq @user1.email
48
+ end
49
+
50
+ it 'should be able to change the current user' do
51
+ name = 'Test Testsson'
52
+ email = 'test@testsson.com'
53
+ nickname = 'test'
54
+
55
+ # User 1 cli interrupt things...
56
+ mock_cli_call(Gas::GitConfig, "git config --global user.name \"#{@name}\"") { nil }
57
+ mock_cli_call(Gas::GitConfig, "git config --global user.email \"#{@email}\"") { nil }
58
+ mock_cli_call(Gas::GitConfig, 'git config --global --get user.name') { @name + "\n" }
59
+ mock_cli_call(Gas::GitConfig, 'git config --global --get user.email') { @email + "\n" }
60
+
61
+ Gas::GitConfig.change_user @user1
62
+
63
+ user = Gas::GitConfig.current_user
64
+ user.name.should eq @name
65
+ user.email.should eq @email # test that the user switch worked (paranoid, huh?)
66
+
67
+ # User 2 cli interrupt things...
68
+ mock_cli_call(Gas::GitConfig, "git config --global user.name \"#{name}\"") { nil }
69
+ mock_cli_call(Gas::GitConfig, "git config --global user.email \"#{email}\"") { nil }
70
+ mock_cli_call(Gas::GitConfig, 'git config --global --get user.name') { name + "\n" }
71
+ mock_cli_call(Gas::GitConfig, 'git config --global --get user.email') { email + "\n" }
72
+
73
+ @user2 = Gas::User.new(name, email, nickname) # create user 2
74
+ Gas::GitConfig.change_user @user2
75
+
76
+ user = Gas::GitConfig.current_user
77
+ user.name.should eq name
78
+ user.email.should eq email # test that the user changed appropriately
79
+ end
80
+
81
+ end
82
+ end
@@ -25,4 +25,22 @@ describe Gas::User do
25
25
  user = Gas::User.new name, email, nickname
26
26
  user.nickname.should == nickname
27
27
  end
28
+
29
+ it 'should be equal if all fields are equal' do
30
+ user1 = Gas::User.new 'foo', 'bar', 'foobar'
31
+ user2 = Gas::User.new 'foo', 'bar', 'foobar'
32
+ user1.should == user2
33
+ end
34
+
35
+ it 'should be equal even with one user missing nickname' do
36
+ user1 = Gas::User.new 'foo', 'bar', 'foobar'
37
+ user2 = Gas::User.new 'foo', 'bar', ''
38
+ user1.should == user2
39
+ end
40
+
41
+ it 'should not be equal if nicknames are set but mismatch' do
42
+ user1 = Gas::User.new 'foo', 'bar', 'foobar'
43
+ user2 = Gas::User.new 'foo', 'bar', 'baz'
44
+ user1.should_not == user2
45
+ end
28
46
  end
@@ -0,0 +1,71 @@
1
+ require './spec/spec_helper'
2
+
3
+ require './lib/gas'
4
+
5
+ describe Gas::Users do
6
+
7
+ before :each do
8
+ @name = 'Fredrik Wallgren'
9
+ @email = 'fredrik.wallgren@gmail.com'
10
+ @nickname = 'walle'
11
+ users = "[#{@nickname}]\n name = #{@name}\n email = #{@email}\n\n[user2]\n name = foo\n email = bar"
12
+ stub.instance_of(Gas::Users).setup! {}
13
+ @users = Gas::Users.new nil
14
+ stub(@users).users { [Gas::User.new(@name, @email, @nickname), Gas::User.new('foo', 'bar', 'user2')] }
15
+ end
16
+
17
+ it 'should be able to parse users from users format' do
18
+ @users.users.count.should be 2
19
+ @users.users[0].name.should eq @name
20
+ @users.users[0].email.should eq @email
21
+ @users.users[0].nickname.should eq @nickname
22
+ end
23
+
24
+ it 'should output the users in the correct format' do
25
+ mock(Gas::GitConfig).current_user { Gas::User.new 'foobar', 'test' }
26
+ @users.to_s.should == " [walle]\n name = Fredrik Wallgren\n email = fredrik.wallgren@gmail.com\n [user2]\n name = foo\n email = bar"
27
+ end
28
+
29
+ it 'should output the users in the correct format with current user' do
30
+ mock(Gas::GitConfig).current_user { Gas::User.new 'foo', 'bar' }
31
+ @users.to_s.should == " [walle]\n name = Fredrik Wallgren\n email = fredrik.wallgren@gmail.com\n ==> [user2]\n name = foo\n email = bar"
32
+ end
33
+
34
+ it 'should be able to tell if a nickname exists' do
35
+ @users.exists?('walle').should be_true
36
+ @users.exists?('foo').should be_false
37
+ @users.exists?('user2').should be_true
38
+ end
39
+
40
+ it 'should be able to get a user from a nickname' do
41
+ user1, user2 = Gas::User.new(@name, @email, @nickname), Gas::User.new('foo', 'bar', 'user2')
42
+ stub(@users).users { [user1, user2] }
43
+ @users.get('walle').should eq user1
44
+ @users.get('user2').should eq user2
45
+ @users['walle'].should eq user1
46
+ @users['user2'].should eq user2
47
+ @users[:walle].should eq user1
48
+ @users[:user2].should eq user2
49
+ end
50
+
51
+ it 'should be able to add users' do
52
+ user1, user2 = Gas::User.new(@name, @email, @nickname), Gas::User.new('foo', 'bar', 'user2')
53
+ @users = Gas::Users.new nil
54
+ @users.add user1
55
+ @users.users.count.should be 1
56
+ @users.add user2
57
+ @users.users.count.should be 2
58
+ end
59
+
60
+ it 'should be able to delete users by nickname' do
61
+ user1, user2 = Gas::User.new(@name, @email, @nickname), Gas::User.new('foo', 'bar', 'user2')
62
+ @users = Gas::Users.new nil
63
+ @users.add user1
64
+ @users.add user2
65
+ @users.users.count.should be 2
66
+ @users.delete @nickname
67
+ @users.users.count.should be 1
68
+ @users.delete 'user2'
69
+ @users.users.count.should be 0
70
+ end
71
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,72 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-18 00:00:00.000000000 Z
12
+ date: 2012-11-18 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: thor
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 0.14.6
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: 0.14.6
30
- - !ruby/object:Gem::Dependency
31
- name: sshkey
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: 1.2.2
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: 1.2.2
46
- - !ruby/object:Gem::Dependency
47
- name: highline
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: json
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :runtime
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
14
  - !ruby/object:Gem::Dependency
79
15
  name: rake
80
16
  requirement: !ruby/object:Gem::Requirement
@@ -139,66 +75,41 @@ dependencies:
139
75
  - - ! '>='
140
76
  - !ruby/object:Gem::Version
141
77
  version: '0'
142
- - !ruby/object:Gem::Dependency
143
- name: vcr
144
- requirement: !ruby/object:Gem::Requirement
145
- none: false
146
- requirements:
147
- - - ! '>='
148
- - !ruby/object:Gem::Version
149
- version: '0'
150
- type: :development
151
- prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
- requirements:
155
- - - ! '>='
156
- - !ruby/object:Gem::Version
157
- version: '0'
158
- - !ruby/object:Gem::Dependency
159
- name: pry
160
- requirement: !ruby/object:Gem::Requirement
161
- none: false
162
- requirements:
163
- - - ! '>='
164
- - !ruby/object:Gem::Version
165
- version: '0'
166
- type: :development
167
- prerelease: false
168
- version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
- requirements:
171
- - - ! '>='
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
78
  description: Gas is a utility to keep track of your git authors. Add them to gas and
175
79
  switch at any time. Great if you use one author at work and one at home or if you
176
- are doing pair programming. Includes SSH support.
80
+ are doing pair programming. Is extendable with own commands.
177
81
  email: fredrik.wallgren@gmail.com
178
82
  executables:
179
83
  - gas
84
+ - gas-add
85
+ - gas-delete
86
+ - gas-import
87
+ - gas-list
88
+ - gas-show
89
+ - gas-use
180
90
  extensions: []
181
91
  extra_rdoc_files:
182
92
  - README.textile
183
93
  - LICENSE
184
94
  files:
185
95
  - bin/gas
186
- - lib/gas/config.rb
187
- - lib/gas/gitconfig.rb
188
- - lib/gas/github_speaker.rb
189
- - lib/gas/prompter.rb
190
- - lib/gas/settings.rb
191
- - lib/gas/ssh.rb
96
+ - bin/gas-add
97
+ - bin/gas-delete
98
+ - bin/gas-import
99
+ - bin/gas-list
100
+ - bin/gas-show
101
+ - bin/gas-use
102
+ - lib/gas/git_config.rb
192
103
  - lib/gas/user.rb
104
+ - lib/gas/users.rb
193
105
  - lib/gas/version.rb
194
106
  - lib/gas.rb
195
- - spec/integration/ssh_spec.rb
107
+ - spec/integration/gas_spec.rb
108
+ - spec/integration/users_spec.rb
196
109
  - spec/spec_helper.rb
197
- - spec/unit/config_spec.rb
198
- - spec/unit/gitconfig_spec.rb
199
- - spec/unit/github_speaker_spec.rb
200
- - spec/unit/settings_spec.rb
110
+ - spec/unit/git_config_spec.rb
201
111
  - spec/unit/user_spec.rb
112
+ - spec/unit/users_spec.rb
202
113
  - LICENSE
203
114
  - README.textile
204
115
  homepage: https://github.com/walle/gas
@@ -216,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
216
127
  version: '0'
217
128
  segments:
218
129
  - 0
219
- hash: 1919630044039596509
130
+ hash: -1416212539312677470
220
131
  required_rubygems_version: !ruby/object:Gem::Requirement
221
132
  none: false
222
133
  requirements:
@@ -225,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
136
  version: '0'
226
137
  segments:
227
138
  - 0
228
- hash: 1919630044039596509
139
+ hash: -1416212539312677470
229
140
  requirements: []
230
141
  rubyforge_project: gas
231
142
  rubygems_version: 1.8.24
@@ -1,148 +0,0 @@
1
- require 'fileutils'
2
-
3
- module Gas
4
-
5
- # Class that keeps track of users
6
- class Config
7
- attr_reader :users
8
-
9
- # This function checks for a ~/.gas FILE and if it exists, it puts it into memory and deletes it from the HDD
10
- # then it creates the ~/.gas FOLDER and saves the old .gas file as ~/git.conf
11
- #
12
- def migrate_to_gas_dir!
13
- old_config_file = GAS_DIRECTORY
14
- config_dir = GAS_DIRECTORY
15
- new_config_file = GAS_DIRECTORY + "/gas.authors"
16
-
17
- if File.file? old_config_file
18
- file = File.open(old_config_file, "rb")
19
- contents = file.read
20
- file.close
21
-
22
- File.delete old_config_file
23
-
24
- Dir::mkdir(config_dir)
25
-
26
- file = File.new(new_config_file, "w")
27
- file.puts contents
28
- file.close
29
- end
30
- end
31
-
32
-
33
- # Initializes the object. If no users are supplied we look for a config file, if none then create it, and parse it to load users
34
- # @param [Array<User>] users The override users
35
- # @param [String] config The override config
36
- def initialize(users = nil, config = nil)
37
- migrate_to_gas_dir! # Migrates old users to the new configuration file location, how thoughtful of me, I know
38
- @config_file = "#{GAS_DIRECTORY}/gas.authors"
39
- @gas_dir = GAS_DIRECTORY
40
- @config = ''
41
-
42
- if config.nil?
43
- if !File.exists? @config_file
44
- Dir::mkdir(@gas_dir)
45
- FileUtils.touch @config_file
46
- end
47
-
48
- @config = File.read(@config_file)
49
- else
50
- @config = config
51
- end
52
-
53
- if users.nil?
54
- @users = []
55
- @config.scan(/\[(.+)\]\s+name = (.+)\s+email = (.+)/) do |nickname, name, email|
56
- @users << User.new(name, email, nickname)
57
- end
58
- else
59
- @users = users
60
- end
61
- end
62
-
63
- # Checks if a user with _nickname_ exists
64
- # @param [String] nickname
65
- # @return [Boolean]
66
- def exists?(nickname)
67
- @users.each do |user|
68
- if user.nickname == nickname
69
- return true;
70
- end
71
- end
72
-
73
- false
74
- end
75
-
76
- # Returns the user with nickname nil if no such user exists
77
- # @param [String|Symbol] nickname
78
- # @return [User|nil]
79
- def get(nickname)
80
- @users.each do |user|
81
- if user.nickname == nickname.to_s
82
- return user
83
- end
84
- end
85
-
86
- nil
87
- end
88
-
89
- # Override [] to get hash style acces to users
90
- # @param [String|Symbol] nickname
91
- # @return [User|nil]
92
- def [](nickname)
93
- get nickname
94
- end
95
-
96
- # Adds a user
97
- # @param [User]
98
- def add(user)
99
- @users << user
100
- end
101
-
102
- # Deletes a user by nickname
103
- # @param [String] nickname The nickname of the user to delete
104
- def delete(nickname)
105
- @users.delete_if do |user|
106
- user.nickname == nickname
107
- end
108
- end
109
-
110
- # Saves the current users to the config file
111
- def save!
112
- File.open @config_file, 'w' do |file|
113
- file.write self
114
- end
115
- end
116
-
117
-
118
- # Override to_s to output correct format
119
- def to_s
120
- gc = Gitconfig.new
121
-
122
- users = @users.map do |user|
123
- if is_current_user(gc.current_user_object[:name], gc.current_user_object[:email], user.to_s)
124
- " ==>" + user.to_s[5,user.to_s.length]
125
- else
126
- user.to_s
127
- end
128
- end.join("\n")
129
-
130
- return users
131
- end
132
-
133
-
134
- # Scans the @users (a string containing info formatted identical to the gas.author file)
135
- # ...and checks to see if it's name and email match what you're looking for
136
- def is_current_user(name, email, object)
137
- object.scan(/\[(.+)\]\s+name = (.+)\s+email = (.+)/) do |nicknamec, namec, emailc|
138
- if namec == name and emailc == email
139
- # check if ssh is active
140
- # TODO: Check if its SSH key is setup, and indicate SSH ACTIVE
141
- return true
142
- end
143
- end
144
- return false # could not get a current user's nickname
145
- end
146
-
147
- end
148
- end