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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0713263b1b47aac699bf0284c07c6fae25ec0c64
4
- data.tar.gz: 3f292a189e77cdb39200411c52506cd93518d973
3
+ metadata.gz: 88dc590dd6d02e8573709bc1036263435ae94e3e
4
+ data.tar.gz: 1d67f3027b98a6306684bf240a18a61bc2bbc674
5
5
  SHA512:
6
- metadata.gz: 735eb9a13455a661717c83cc7f45abd4a086c7f970ff7399882d3dbf89717c9e3d197d7a30ca28e5f417f88652c73bacf9a386fc69b0eb1c53166cf299b7ccb9
7
- data.tar.gz: 68b19a18b16e2b836882060236b60cf8c06c0f1eee5bd60ab93ba2c4fed758139646194145717b4a7773baa69e8ba76f8e6c64c2499389494418dc72d12444c3
6
+ metadata.gz: 3ebb360390d5e265a5ad3cab2c0e31e56c79360fc46571b1da14138d96f33270e50268e66c2b5cad30a13d9845c0370203e817223e9754dd2d7855cf9923a6fd
7
+ data.tar.gz: 12b092bb719569d7a7df2f63c4def931f549e4e41e77561a002053abae2dc3a12d61b471a4b3f6e0b1b9b36c8bf835e061138face5cc2dfb742d789c5aa2476a
data/.travis.yml CHANGED
@@ -6,3 +6,5 @@ before_install:
6
6
  - gem update --system
7
7
  services:
8
8
  - redis-server
9
+ notifications:
10
+ email: false
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # lita-wizard
2
2
 
3
3
  [![Build Status](https://travis-ci.org/cristianbica/lita-wizard.png?branch=master)](https://travis-ci.org/cristianbica/lita-wizard)
4
- [![Coverage Status](https://coveralls.io/repos/cristianbica/lita-wizard/badge.png)](https://coveralls.io/r/cristianbica/lita-wizard)
4
+ [![Coverage Status](https://coveralls.io/repos/github/cristianbica/lita-wizard/badge.svg?branch=master)](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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-wizard"
3
- spec.version = "1.0.0"
3
+ spec.version = "1.0.1"
4
4
  spec.authors = ["Cristian Bica"]
5
5
  spec.email = ["cristian.bica@gmail.com"]
6
6
  spec.description = "A lita extension to build wizards"
@@ -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 eq("initial message")
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
@@ -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", :focus do
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)#.with(robot, message, data)
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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-wizard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cristian Bica