me 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Gemfile +2 -0
- data/README.md +4 -2
- data/bin/me +6 -0
- data/lib/me/activation.rb +39 -0
- data/lib/me/activation_view_model.rb +5 -0
- data/lib/me/cli/activate_command.rb +30 -0
- data/lib/me/cli/activation_view.rb +23 -0
- data/lib/me/cli/active_identity_view.rb +11 -0
- data/lib/me/cli/git_config_command.rb +23 -0
- data/lib/me/cli/git_config_view.rb +11 -0
- data/lib/me/cli/git_not_configured_view.rb +9 -0
- data/lib/me/cli/new_active_identity_view.rb +11 -0
- data/lib/me/cli/ssh_config_command.rb +23 -0
- data/lib/me/cli/ssh_config_view.rb +17 -0
- data/lib/me/cli/ssh_not_configured_view.rb +9 -0
- data/lib/me/cli/switch_command.rb +45 -0
- data/lib/me/cli/whoami_command.rb +18 -0
- data/lib/me/cli.rb +86 -0
- data/lib/me/error_presenter.rb +36 -0
- data/lib/me/errors.rb +32 -0
- data/lib/me/executor.rb +15 -0
- data/lib/me/git_activation.rb +30 -0
- data/lib/me/git_config.rb +71 -0
- data/lib/me/git_config_view_model.rb +5 -0
- data/lib/me/identity.rb +64 -0
- data/lib/me/identity_view_model.rb +5 -0
- data/lib/me/mappers/git_config_store2.rb +65 -0
- data/lib/me/mappers/identity_store2.rb +40 -0
- data/lib/me/mappers/ssh_config_store2.rb +68 -0
- data/lib/me/registry.rb +54 -0
- data/lib/me/ssh_activation.rb +28 -0
- data/lib/me/ssh_config.rb +65 -0
- data/lib/me/ssh_config_view_model.rb +5 -0
- data/lib/me/store2.rb +147 -0
- data/lib/me/thread_scope.rb +29 -0
- data/lib/me/version.rb +1 -1
- data/lib/me/view.rb +15 -0
- data/me.gemspec +2 -0
- data/spec/me/activation_spec.rb +22 -0
- data/spec/me/cli/activate_command_spec.rb +56 -0
- data/spec/me/cli/git_config_command_spec.rb +53 -0
- data/spec/me/cli/ssh_config_command_spec.rb +54 -0
- data/spec/me/cli/switch_command_spec.rb +64 -0
- data/spec/me/cli/whoami_command_spec.rb +26 -0
- data/spec/me/executor_spec.rb +23 -0
- data/spec/me/git_config_spec.rb +150 -0
- data/spec/me/identity_spec.rb +101 -0
- data/spec/me/mappers/git_config_store2_spec.rb +71 -0
- data/spec/me/mappers/identity_store2_spec.rb +37 -0
- data/spec/me/mappers/ssh_config_store2_spec.rb +65 -0
- data/spec/me/ssh_config_spec.rb +125 -0
- data/spec/me/store2_spec.rb +151 -0
- data/spec/spec_helper.rb +38 -0
- data/test.sh +38 -0
- metadata +85 -4
@@ -0,0 +1,53 @@
|
|
1
|
+
require "me/cli/git_config_command"
|
2
|
+
require "me/registry"
|
3
|
+
|
4
|
+
module Me
|
5
|
+
module Cli
|
6
|
+
RSpec.describe GitConfigCommand do
|
7
|
+
subject(:command) { described_class.new(identity_name, name, email) }
|
8
|
+
|
9
|
+
let(:identity_name) { double("Identity Name") }
|
10
|
+
|
11
|
+
let(:git_config) { instance_double(GitConfig, configure: nil) }
|
12
|
+
let(:actual_git_config) { instance_double(GitConfig) }
|
13
|
+
|
14
|
+
let(:mapper_factory) { class_double(GitConfig::Mapper) }
|
15
|
+
let(:mapper) { instance_double(GitConfig::Mapper, find: git_config) }
|
16
|
+
|
17
|
+
before do
|
18
|
+
Registry.register_git_config_mapper_factory(mapper_factory)
|
19
|
+
|
20
|
+
allow(mapper_factory)
|
21
|
+
.to receive(:new)
|
22
|
+
.with(name, email, identity_name)
|
23
|
+
.and_return(mapper)
|
24
|
+
|
25
|
+
allow(mapper_factory)
|
26
|
+
.to receive(:find_by_identity)
|
27
|
+
.with(identity_name)
|
28
|
+
.and_return(actual_git_config)
|
29
|
+
|
30
|
+
allow(actual_git_config)
|
31
|
+
.to receive(:build_view)
|
32
|
+
.with(GitConfigView)
|
33
|
+
.and_return(GitConfigView.new(name: name, email: email))
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#call" do
|
37
|
+
context "when name and email specified" do
|
38
|
+
let(:name) { "john" }
|
39
|
+
let(:email) { "john@example.org" }
|
40
|
+
|
41
|
+
it "configures git" do
|
42
|
+
expect(git_config).to receive(:configure).once
|
43
|
+
command.call
|
44
|
+
end
|
45
|
+
|
46
|
+
it "renders new configuration" do
|
47
|
+
expect(command.call.to_s).to eq("name: john\nemail: john@example.org")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "me/cli/ssh_config_command"
|
2
|
+
require "me/registry"
|
3
|
+
|
4
|
+
module Me
|
5
|
+
module Cli
|
6
|
+
RSpec.describe SshConfigCommand do
|
7
|
+
subject(:command) { described_class.new(identity_name, keys) }
|
8
|
+
|
9
|
+
let(:identity_name) { double("Identity Name") }
|
10
|
+
|
11
|
+
let(:ssh_config) { instance_double(SshConfig, configure: nil) }
|
12
|
+
let(:actual_ssh_config) { instance_double(SshConfig) }
|
13
|
+
|
14
|
+
let(:expected_keys) { ["id_rsa", "id_dsa", "github.rsa"] }
|
15
|
+
|
16
|
+
let(:mapper_factory) { class_double(SshConfig::Mapper) }
|
17
|
+
let(:mapper) { instance_double(SshConfig::Mapper, find: ssh_config) }
|
18
|
+
|
19
|
+
before do
|
20
|
+
Registry.register_ssh_config_mapper_factory(mapper_factory)
|
21
|
+
|
22
|
+
allow(mapper_factory)
|
23
|
+
.to receive(:new)
|
24
|
+
.with(keys, identity_name)
|
25
|
+
.and_return(mapper)
|
26
|
+
|
27
|
+
allow(mapper_factory)
|
28
|
+
.to receive(:find_by_identity)
|
29
|
+
.with(identity_name)
|
30
|
+
.and_return(actual_ssh_config)
|
31
|
+
|
32
|
+
allow(actual_ssh_config)
|
33
|
+
.to receive(:build_view)
|
34
|
+
.with(SshConfigView)
|
35
|
+
.and_return(SshConfigView.new(keys: expected_keys))
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#call" do
|
39
|
+
context "when there are some keys" do
|
40
|
+
let(:keys) { instance_double(Array, empty?: false) }
|
41
|
+
|
42
|
+
it "configures ssh with this keys" do
|
43
|
+
expect(ssh_config).to receive(:configure).once
|
44
|
+
command.call
|
45
|
+
end
|
46
|
+
|
47
|
+
it "responds with new key list" do
|
48
|
+
expect(command.call.to_s).to eq("keys:\n- id_rsa\n- id_dsa\n- github.rsa")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "me/cli/switch_command"
|
2
|
+
require "me/registry"
|
3
|
+
|
4
|
+
module Me
|
5
|
+
module Cli
|
6
|
+
RSpec.describe SwitchCommand do
|
7
|
+
subject(:command) { described_class.new(name) }
|
8
|
+
|
9
|
+
let(:name) { double("Name") }
|
10
|
+
|
11
|
+
let(:identity) { double("Identity") }
|
12
|
+
let(:mapper_factory) { class_double(Identity::Mapper) }
|
13
|
+
let(:mapper) { instance_double(Identity::Mapper, find: identity) }
|
14
|
+
|
15
|
+
let(:active_identity) { double("Active Identity") }
|
16
|
+
|
17
|
+
let(:activate_command) { instance_double(ActivateCommand, call: activation_views) }
|
18
|
+
let(:activation_views) { [activation_view_a, activation_view_b] }
|
19
|
+
|
20
|
+
let(:activation_view_a) { double("View") }
|
21
|
+
let(:activation_view_b) { double("View") }
|
22
|
+
|
23
|
+
before do
|
24
|
+
Registry.register_identity_mapper_factory(mapper_factory)
|
25
|
+
|
26
|
+
allow(Identity).to receive(:active).and_return(active_identity)
|
27
|
+
allow(identity).to receive(:activate)
|
28
|
+
allow(active_identity)
|
29
|
+
.to receive(:build_view)
|
30
|
+
.with(NewActiveIdentityView)
|
31
|
+
.and_return(NewActiveIdentityView.new(name: "new_identity"))
|
32
|
+
|
33
|
+
allow(mapper_factory)
|
34
|
+
.to receive(:new)
|
35
|
+
.with(name)
|
36
|
+
.and_return(mapper)
|
37
|
+
|
38
|
+
allow(ActivateCommand)
|
39
|
+
.to receive(:new)
|
40
|
+
.and_return(activate_command)
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#call" do
|
44
|
+
it "activates new identity" do
|
45
|
+
expect(identity).to receive(:activate).once
|
46
|
+
command.call
|
47
|
+
end
|
48
|
+
|
49
|
+
it "activates configuration" do
|
50
|
+
expect(activate_command).to receive(:call).and_return(activation_views)
|
51
|
+
command.call
|
52
|
+
end
|
53
|
+
|
54
|
+
it "responds with new active identity" do
|
55
|
+
expect(command.call[0].to_s).to eq("New active identity: new_identity")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "responds with activation views too" do
|
59
|
+
expect(command.call[1..-1]).to eq(activation_views)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "me/cli/whoami_command"
|
2
|
+
require "me/registry"
|
3
|
+
|
4
|
+
module Me
|
5
|
+
module Cli
|
6
|
+
RSpec.describe WhoamiCommand do
|
7
|
+
subject(:command) { described_class.new }
|
8
|
+
|
9
|
+
let(:identity) { instance_double(Identity) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(Identity).to receive(:active).and_return(identity)
|
13
|
+
allow(identity)
|
14
|
+
.to receive(:build_view)
|
15
|
+
.with(ActiveIdentityView)
|
16
|
+
.and_return(ActiveIdentityView.new(name: "personal"))
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#call" do
|
20
|
+
it "has expected response" do
|
21
|
+
expect(command.call.to_s).to eq("Active identity: personal")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "me/executor"
|
2
|
+
|
3
|
+
module Me
|
4
|
+
RSpec.describe Executor do
|
5
|
+
subject(:executor) { described_class.new }
|
6
|
+
|
7
|
+
let(:args) { [double("arg"), double("arg"), double("arg")] }
|
8
|
+
let(:kernel) { double("Kernel") }
|
9
|
+
|
10
|
+
before do
|
11
|
+
Registry.register_kernel(kernel)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#call" do
|
15
|
+
it "delegates to kernel" do
|
16
|
+
expect(kernel)
|
17
|
+
.to receive(:system)
|
18
|
+
.with(*args)
|
19
|
+
executor.call(args)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require "me/git_config"
|
2
|
+
require "me/activation"
|
3
|
+
require "me/executor"
|
4
|
+
require "me/registry"
|
5
|
+
|
6
|
+
module Me
|
7
|
+
RSpec.describe GitConfig do
|
8
|
+
subject(:git_config) { GitConfig.new(name, email, identity_name).with_mapper(mapper) }
|
9
|
+
|
10
|
+
let(:name) { "sarah" }
|
11
|
+
let(:email) { "sarah.o@example.org" }
|
12
|
+
|
13
|
+
let(:identity_name) { "sarah_personal" }
|
14
|
+
|
15
|
+
let(:mapper_factory) { class_double(GitConfig::Mapper) }
|
16
|
+
let(:mapper) { instance_double(GitConfig::Mapper) }
|
17
|
+
|
18
|
+
let(:git_config_hash) { { "name" => name, "email" => email } }
|
19
|
+
|
20
|
+
let(:executor_factory) { class_double(Executor, new: executor) }
|
21
|
+
let(:executor) { instance_double(Executor, call: nil) }
|
22
|
+
|
23
|
+
before do
|
24
|
+
Registry.register_git_config_mapper_factory(mapper_factory)
|
25
|
+
allow(mapper_factory)
|
26
|
+
.to receive(:find_by_identity)
|
27
|
+
.with(identity_name)
|
28
|
+
.and_return(git_config)
|
29
|
+
|
30
|
+
Registry.register_executor_factory(executor_factory)
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#initialize" do
|
34
|
+
it "creates and object out of name and email" do
|
35
|
+
expect(GitConfig.new("john", "john@example.org", identity_name))
|
36
|
+
.to eq(GitConfig.new("john", "john@example.org", identity_name))
|
37
|
+
end
|
38
|
+
|
39
|
+
it "can be created with identity" do
|
40
|
+
expect(GitConfig.new("john", "john@example.org", identity_name))
|
41
|
+
.to eq(GitConfig.new("john", "john@example.org", identity_name))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#==" do
|
46
|
+
it "is equal to git config with the same name and email" do
|
47
|
+
expect(GitConfig.new("james", "james.black@example.org", identity_name))
|
48
|
+
.to eq(GitConfig.new("james", "james.black@example.org", identity_name))
|
49
|
+
end
|
50
|
+
|
51
|
+
it "is not equal to git config with different name or email" do
|
52
|
+
expect(GitConfig.new("james", "james.black@example.org", identity_name))
|
53
|
+
.not_to eq(GitConfig.new("john", "james.black@example.org", identity_name))
|
54
|
+
|
55
|
+
expect(GitConfig.new("james", "james.black@example.org", identity_name))
|
56
|
+
.not_to eq(GitConfig.new("james", "john.smith@example.org", identity_name))
|
57
|
+
|
58
|
+
expect(GitConfig.new("james", "james.black@example.org", identity_name))
|
59
|
+
.not_to eq(GitConfig.new("john", "john.smith@example.org", identity_name))
|
60
|
+
end
|
61
|
+
|
62
|
+
it "handles edge cases properly" do
|
63
|
+
expect(GitConfig.new("james", "james.black@example.org", identity_name)).not_to eq(nil)
|
64
|
+
expect(GitConfig.new("james", "james.black@example.org", identity_name)).not_to eq(Object.new)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "doesn't care about identity" do
|
68
|
+
expect(GitConfig.new("james", "james.black@example.org", identity_name))
|
69
|
+
.to eq(GitConfig.new("james", "james.black@example.org", "different name"))
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe ".for_identity" do
|
74
|
+
subject(:git_config_from_identity) { GitConfig.for_identity(identity_name) }
|
75
|
+
let(:a_git_config) { instance_double(GitConfig) }
|
76
|
+
|
77
|
+
before do
|
78
|
+
allow(mapper_factory)
|
79
|
+
.to receive(:find_by_identity)
|
80
|
+
.with(identity_name)
|
81
|
+
.and_return(a_git_config)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "finds git config for specified identity" do
|
85
|
+
expect(git_config_from_identity).to eq(a_git_config)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#configure" do
|
90
|
+
context "when name and email are present" do
|
91
|
+
it "delegates to store to configure git" do
|
92
|
+
expect(mapper)
|
93
|
+
.to receive(:update)
|
94
|
+
.with(name: name, email: email)
|
95
|
+
.once
|
96
|
+
|
97
|
+
git_config.configure
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "when name or email is not present" do
|
102
|
+
let(:name) { nil }
|
103
|
+
let(:email) { nil }
|
104
|
+
|
105
|
+
it "does nothing" do
|
106
|
+
expect(mapper).not_to receive(:update)
|
107
|
+
git_config.configure
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#build_view" do
|
113
|
+
let(:view_factory) { double("ViewFactory") }
|
114
|
+
let(:view) { double("View") }
|
115
|
+
|
116
|
+
it "gives name and email to view factory" do
|
117
|
+
allow(view_factory)
|
118
|
+
.to receive(:new)
|
119
|
+
.with(name: name, email: email)
|
120
|
+
.and_return(view)
|
121
|
+
expect(git_config.build_view(view_factory)).to eq(view)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "#activate" do
|
126
|
+
it "sets up global git user.email config" do
|
127
|
+
expect(executor)
|
128
|
+
.to receive(:call)
|
129
|
+
.with(["git", "config", "--global", "user.email", email])
|
130
|
+
git_config.activate
|
131
|
+
end
|
132
|
+
|
133
|
+
it "sets up global git user.name config" do
|
134
|
+
expect(executor)
|
135
|
+
.to receive(:call)
|
136
|
+
.with(["git", "config", "--global", "user.name", name])
|
137
|
+
git_config.activate
|
138
|
+
end
|
139
|
+
|
140
|
+
it "returns an activation" do
|
141
|
+
expect(git_config.activate).to eq(
|
142
|
+
Activation.new._with_commands([
|
143
|
+
["git", "config", "--global", "user.name", name],
|
144
|
+
["git", "config", "--global", "user.email", email],
|
145
|
+
])
|
146
|
+
)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require "me/identity"
|
2
|
+
require "me/git_config"
|
3
|
+
require "me/ssh_config"
|
4
|
+
require "me/registry"
|
5
|
+
|
6
|
+
module Me
|
7
|
+
RSpec.describe Identity do
|
8
|
+
subject(:identity) { Identity.new(name).with_mapper(mapper) }
|
9
|
+
|
10
|
+
let(:name) { "john" }
|
11
|
+
|
12
|
+
let(:mapper_factory) { class_double(Identity::Mapper, new: active_mapper) }
|
13
|
+
let(:active_mapper) { instance_double(Identity::Mapper) }
|
14
|
+
let(:mapper) { instance_double(Identity::Mapper) }
|
15
|
+
|
16
|
+
let(:git_config) { instance_double(GitConfig) }
|
17
|
+
let(:ssh_config) { instance_double(SshConfig) }
|
18
|
+
|
19
|
+
before do
|
20
|
+
Registry.register_identity_mapper_factory(mapper_factory)
|
21
|
+
allow(mapper_factory)
|
22
|
+
.to receive(:new)
|
23
|
+
.with(name)
|
24
|
+
.and_return(mapper)
|
25
|
+
|
26
|
+
allow(GitConfig)
|
27
|
+
.to receive(:for_identity)
|
28
|
+
.with(name)
|
29
|
+
.and_return(git_config)
|
30
|
+
|
31
|
+
allow(SshConfig)
|
32
|
+
.to receive(:for_identity)
|
33
|
+
.with(name)
|
34
|
+
.and_return(ssh_config)
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#initialize" do
|
38
|
+
it "can be created with name" do
|
39
|
+
expect(Identity.new("john")).to eq(Identity.new("john"))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#==" do
|
44
|
+
it "is equal to the identity with the same name" do
|
45
|
+
expect(Identity.new("james")).to eq(Identity.new("james"))
|
46
|
+
end
|
47
|
+
|
48
|
+
it "is not equal to the identity with different name" do
|
49
|
+
expect(Identity.new("james")).not_to eq(Identity.new("john"))
|
50
|
+
end
|
51
|
+
|
52
|
+
it "handles edge cases properly" do
|
53
|
+
expect(Identity.new("james")).not_to eq(nil)
|
54
|
+
expect(Identity.new("sarah")).not_to eq(Object.new)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe ".active" do
|
59
|
+
it "returns active identity" do
|
60
|
+
expected = instance_double(Identity)
|
61
|
+
allow(active_mapper).to receive(:find).and_return(expected)
|
62
|
+
expect(Identity.active).to eq(expected)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#build_view" do
|
67
|
+
let(:view_factory) { double("ViewFactory") }
|
68
|
+
let(:view) { double("View") }
|
69
|
+
|
70
|
+
before do
|
71
|
+
allow(view_factory)
|
72
|
+
.to receive(:new)
|
73
|
+
.with(name: name)
|
74
|
+
.and_return(view)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "gives the view its name" do
|
78
|
+
expect(identity.build_view(view_factory)).to eq(view)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#activate" do
|
83
|
+
it "calls update on mapper with active_identity = name" do
|
84
|
+
expect(mapper).to receive(:update).with(active_identity: name).once
|
85
|
+
identity.activate
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#git_config" do
|
90
|
+
it "returns git config for this identity" do
|
91
|
+
expect(identity.git_config).to eq(git_config)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#ssh_config" do
|
96
|
+
it "returns ssh config for this identity" do
|
97
|
+
expect(identity.ssh_config).to eq(ssh_config)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "me/mappers/git_config_store2"
|
2
|
+
|
3
|
+
module Me
|
4
|
+
module Mappers
|
5
|
+
RSpec.describe GitConfigStore2 do
|
6
|
+
let(:email) { "john@example.org" }
|
7
|
+
let(:name) { "John Smith" }
|
8
|
+
let(:identity) { "john_personal" }
|
9
|
+
|
10
|
+
before do
|
11
|
+
described_class.new(name, email, identity).update(name: name, email: email)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe ".find_by_identity" do
|
15
|
+
it "finds an identity if it is present" do
|
16
|
+
expect(described_class.find_by_identity(identity))
|
17
|
+
.to eq(GitConfig.new(name, email, identity))
|
18
|
+
end
|
19
|
+
|
20
|
+
it "fails with GitNotConfigured error if git configuration is not present" do
|
21
|
+
expect {
|
22
|
+
described_class.find_by_identity("other")
|
23
|
+
}.to raise_error(Errors::GitNotConfigured)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#find" do
|
28
|
+
it "returns GitConfig with same attributes" do
|
29
|
+
expect(described_class.new("a name", "a email", "a identity").find)
|
30
|
+
.to eq(GitConfig.new("a name", "a email", "a identity"))
|
31
|
+
end
|
32
|
+
|
33
|
+
it "fails with GitNotConfigured when name or email is not provided" do
|
34
|
+
expect {
|
35
|
+
described_class.new(nil, "a email", "a identity").find
|
36
|
+
}.to raise_error(Errors::GitNotConfigured)
|
37
|
+
|
38
|
+
expect {
|
39
|
+
described_class.new("a name", nil, "a identity").find
|
40
|
+
}.to raise_error(Errors::GitNotConfigured)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "populates GitConfig with missing attributes if it is able to find it" do
|
44
|
+
expect(described_class.new(nil, "a email", identity).find)
|
45
|
+
.to eq(GitConfig.new(name, "a email", identity))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#update" do
|
50
|
+
it "allows to update name" do
|
51
|
+
described_class.new("a name", "a email", identity).update(name: "John")
|
52
|
+
expect(described_class.find_by_identity(identity))
|
53
|
+
.to eq(GitConfig.new("John", email, identity))
|
54
|
+
end
|
55
|
+
|
56
|
+
it "allows to update email" do
|
57
|
+
described_class.new("a name", "a email", identity).update(email: "john@corporation.com")
|
58
|
+
expect(described_class.find_by_identity(identity))
|
59
|
+
.to eq(GitConfig.new(name, "john@corporation.com", identity))
|
60
|
+
end
|
61
|
+
|
62
|
+
it "allows to create new configuration" do
|
63
|
+
described_class.new("a name", "a email", "an identity")
|
64
|
+
.update(name: "James", email: "james@corporation.com")
|
65
|
+
expect(described_class.find_by_identity("an identity"))
|
66
|
+
.to eq(GitConfig.new("James", "james@corporation.com", "an identity"))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "me/mappers/identity_store2"
|
2
|
+
|
3
|
+
module Me
|
4
|
+
module Mappers
|
5
|
+
RSpec.describe IdentityStore2 do
|
6
|
+
subject(:mapper) { described_class.new(name) }
|
7
|
+
subject(:active_mapper) { described_class.new }
|
8
|
+
|
9
|
+
let(:name) { "sarah" }
|
10
|
+
let(:active_identity) { "james" }
|
11
|
+
|
12
|
+
before do
|
13
|
+
store = Store2.build
|
14
|
+
store.set("active_identity", active_identity)
|
15
|
+
store.save
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#find" do
|
19
|
+
it "returns identity with specified name" do
|
20
|
+
expect(mapper.find)
|
21
|
+
.to eq(Identity.new(name))
|
22
|
+
|
23
|
+
expect(active_mapper.find)
|
24
|
+
.to eq(Identity.new(active_identity))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#update" do
|
29
|
+
it "allows to change active identity" do
|
30
|
+
mapper.update(active_identity: "john")
|
31
|
+
expect(active_mapper.find)
|
32
|
+
.to eq(Identity.new("john"))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "me/mappers/ssh_config_store2"
|
2
|
+
|
3
|
+
module Me
|
4
|
+
module Mappers
|
5
|
+
RSpec.describe SshConfigStore2 do
|
6
|
+
let(:keys) { ["id_rsa", "id_dsa", "github.rsa"] }
|
7
|
+
let(:identity) { "work" }
|
8
|
+
|
9
|
+
before do
|
10
|
+
described_class.new(keys, identity).update(keys: keys)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".find_by_identity" do
|
14
|
+
it "returns SshConfig instance with provided identity given it is present" do
|
15
|
+
expect(described_class.find_by_identity(identity))
|
16
|
+
.to eq(SshConfig.new(keys, identity))
|
17
|
+
end
|
18
|
+
|
19
|
+
it "fails with SshNotConfigured error if provided identity is not present" do
|
20
|
+
expect {
|
21
|
+
described_class.find_by_identity("another identity")
|
22
|
+
}.to raise_error(Errors::SshNotConfigured)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#find" do
|
27
|
+
it "returns SshConfig with same attributes" do
|
28
|
+
expect(described_class.new(["a key", "another key"], "an identity").find)
|
29
|
+
.to eq(SshConfig.new(["a key", "another key"], "an identity"))
|
30
|
+
end
|
31
|
+
|
32
|
+
it "fails with SshNotConfigured error if keys are not present" do
|
33
|
+
expect {
|
34
|
+
described_class.new(nil, "an identity").find
|
35
|
+
}.to raise_error(Errors::SshNotConfigured)
|
36
|
+
|
37
|
+
expect {
|
38
|
+
described_class.new([], "an identity").find
|
39
|
+
}.to raise_error(Errors::SshNotConfigured)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "populates SshConfig if it is able to find it" do
|
43
|
+
expect(described_class.new(nil, identity).find)
|
44
|
+
.to eq(SshConfig.new(keys, identity))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#update" do
|
49
|
+
it "allows to update keys" do
|
50
|
+
keys = ["rsa key", "another key", "new key"]
|
51
|
+
described_class.new(["a key", "another key"], identity).update(keys: keys)
|
52
|
+
expect(described_class.find_by_identity(identity))
|
53
|
+
.to eq(SshConfig.new(keys, identity))
|
54
|
+
end
|
55
|
+
|
56
|
+
it "is able to create new configuration" do
|
57
|
+
keys = ["rsa key", "another key", "new key"]
|
58
|
+
described_class.new(keys, "another identity").update(keys: keys)
|
59
|
+
expect(described_class.find_by_identity("another identity"))
|
60
|
+
.to eq(SshConfig.new(keys, "another identity"))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|