lita-wizard 1.0.0 → 1.0.1
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/.travis.yml +2 -0
- data/README.md +1 -1
- data/lib/lita/wizard.rb +4 -0
- data/lita-wizard.gemspec +1 -1
- data/spec/lita/integration_spec.rb +7 -3
- data/spec/lita/wizard_spec.rb +29 -4
- data/spec/support/test_wizard.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88dc590dd6d02e8573709bc1036263435ae94e3e
|
4
|
+
data.tar.gz: 1d67f3027b98a6306684bf240a18a61bc2bbc674
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ebb360390d5e265a5ad3cab2c0e31e56c79360fc46571b1da14138d96f33270e50268e66c2b5cad30a13d9845c0370203e817223e9754dd2d7855cf9923a6fd
|
7
|
+
data.tar.gz: 12b092bb719569d7a7df2f63c4def931f549e4e41e77561a002053abae2dc3a12d61b471a4b3f6e0b1b9b36c8bf835e061138face5cc2dfb742d789c5aa2476a
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# lita-wizard
|
2
2
|
|
3
3
|
[](https://travis-ci.org/cristianbica/lita-wizard)
|
4
|
-
[](https://coveralls.io/github/cristianbica/lita-wizard?branch=master)
|
5
5
|
|
6
6
|
A lita extension to build wizards (surveys, standups, etc). You can instruct your chat bot to ask several questions, validate responses.
|
7
7
|
|
data/lib/lita/wizard.rb
CHANGED
@@ -182,6 +182,10 @@ class Lita::Wizard
|
|
182
182
|
Lita.redis["pending-wizard-#{user_id.downcase}"]
|
183
183
|
end
|
184
184
|
|
185
|
+
def cancel_wizard(user_id)
|
186
|
+
Lita.redis.del "pending-wizard-#{user_id.downcase}"
|
187
|
+
end
|
188
|
+
|
185
189
|
def step(name, options = {})
|
186
190
|
steps << OpenStruct.new(options.merge(name: name))
|
187
191
|
end
|
data/lita-wizard.gemspec
CHANGED
@@ -19,7 +19,7 @@ describe Lita::Handlers::Wizard, lita: true, lita_handler: true do
|
|
19
19
|
it "should reply with the initial message if it's the first step" do
|
20
20
|
message = Lita::Message.new(robot, "test", source)
|
21
21
|
TestWizard.start(robot, message)
|
22
|
-
expect(replies.first).to
|
22
|
+
expect(replies.first).to match(/^initial message/)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should call the start_wizard method if it's the first step" do
|
@@ -101,7 +101,6 @@ describe Lita::Handlers::Wizard, lita: true, lita_handler: true do
|
|
101
101
|
it "should abort the wizard if requested by the user" do
|
102
102
|
store_wizard(current_step_index: 0)
|
103
103
|
send_message("abort", privately: true)
|
104
|
-
puts replies.inspect
|
105
104
|
expect(Lita::Wizard.pending_wizard?("1")).to be_falsey
|
106
105
|
end
|
107
106
|
|
@@ -117,6 +116,11 @@ describe Lita::Handlers::Wizard, lita: true, lita_handler: true do
|
|
117
116
|
send_message("abort", privately: true)
|
118
117
|
end
|
119
118
|
|
120
|
-
|
119
|
+
it "should abort the wizard if it cannot identify the current step" do
|
120
|
+
expect_any_instance_of(TestWizard).to receive(:destroy)
|
121
|
+
store_wizard(current_step_index: 42)
|
122
|
+
send_message("one", privately: true)
|
123
|
+
expect(replies.last).to match /Some error occured. Aborting/
|
124
|
+
end
|
121
125
|
|
122
126
|
end
|
data/spec/lita/wizard_spec.rb
CHANGED
@@ -7,15 +7,15 @@ describe Lita::Wizard, lita: true do
|
|
7
7
|
let(:message) { Lita::Message.new(robot, "test", Lita::Source.new(user: user, room: room, private_message: false)) }
|
8
8
|
|
9
9
|
context "starting a wizard" do
|
10
|
-
after { Lita::Wizard.start(robot, message) }
|
11
10
|
it "should check if a pending wizard exists for that user" do
|
12
11
|
expect(Lita::Wizard).to receive(:pending_wizard?).with("42").and_return(true)
|
13
|
-
|
12
|
+
Lita::Wizard.start(robot, message)
|
14
13
|
end
|
15
14
|
|
16
15
|
it "should try to start a new wizard if a pending one exists" do
|
17
16
|
allow(Lita::Wizard).to receive(:pending_wizard?).and_return(true)
|
18
17
|
expect(Lita::Wizard).to receive(:new).never
|
18
|
+
Lita::Wizard.start(robot, message)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should initialize a new wizard class an advance" do
|
@@ -23,6 +23,12 @@ describe Lita::Wizard, lita: true do
|
|
23
23
|
expect(mocked_wizard).to receive(:advance)
|
24
24
|
allow(Lita::Wizard).to receive(:pending_wizard?).and_return(false)
|
25
25
|
expect(Lita::Wizard).to receive(:new).and_return(mocked_wizard)
|
26
|
+
Lita::Wizard.start(robot, message)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should be able to start a wizard from a handler" do
|
30
|
+
expect(TestWizard).to receive(:start).with(robot, "message", "meta")
|
31
|
+
Lita::Handler.new(robot).start_wizard(TestWizard, "message", "meta")
|
26
32
|
end
|
27
33
|
end
|
28
34
|
|
@@ -53,13 +59,14 @@ describe Lita::Wizard, lita: true do
|
|
53
59
|
end
|
54
60
|
|
55
61
|
it "should return nil if data is malformed" do
|
62
|
+
Lita.redis["pending-wizard-42"] = "x"
|
56
63
|
expect(Lita::Wizard.restore(robot, message)).to be_nil
|
57
64
|
end
|
58
65
|
|
59
|
-
it "should restore the wizard"
|
66
|
+
it "should restore the wizard" do
|
60
67
|
data = { class: "TestWizard", arg1: "43" }
|
61
68
|
Lita.redis["pending-wizard-42"] = data.to_json
|
62
|
-
expect(TestWizard).to receive(:new)
|
69
|
+
expect(TestWizard).to receive(:new)
|
63
70
|
Lita::Wizard.restore(robot, message)
|
64
71
|
end
|
65
72
|
end
|
@@ -74,4 +81,22 @@ describe Lita::Wizard, lita: true do
|
|
74
81
|
expect(Lita::Wizard.pending_wizard?("42")).to be_falsey
|
75
82
|
end
|
76
83
|
end
|
84
|
+
|
85
|
+
context "deleting a wizard" do
|
86
|
+
it "should delete a wizard" do
|
87
|
+
Lita.redis["pending-wizard-42"] = "1"
|
88
|
+
expect(Lita::Wizard.pending_wizard?("42")).to be_truthy
|
89
|
+
Lita::Wizard.cancel_wizard("42")
|
90
|
+
expect(Lita::Wizard.pending_wizard?("42")).to be_falsey
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "accessing answers" do
|
95
|
+
it "should be able to get a specific answer" do
|
96
|
+
data = { class: "TestWizard", values: %w(a b c d) }
|
97
|
+
Lita.redis["pending-wizard-42"] = data.to_json
|
98
|
+
wizard = Lita::Wizard.restore(robot, message)
|
99
|
+
expect(wizard.value_for(:two)).to eq("b")
|
100
|
+
end
|
101
|
+
end
|
77
102
|
end
|
data/spec/support/test_wizard.rb
CHANGED
@@ -24,15 +24,15 @@ class TestWizard < Lita::Wizard
|
|
24
24
|
options: %w(one two)
|
25
25
|
|
26
26
|
def initial_message
|
27
|
-
"initial message"
|
27
|
+
"initial message" << super
|
28
28
|
end
|
29
29
|
|
30
30
|
def abort_message
|
31
|
-
"abort message"
|
31
|
+
"abort message" << super
|
32
32
|
end
|
33
33
|
|
34
34
|
def final_message
|
35
|
-
"final message"
|
35
|
+
"final message" << super
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|