Skip to content

Commit 832d743

Browse files
author
Ben Lavender
authored
Merge pull request #18 from github/prefix-in-tests
Allow setting a prefix in test
2 parents f903004 + 4900e5b commit 832d743

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

lib/chatops/controller/test_case_helpers.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ def chatops_auth!
66
request.env["CHATOPS_TESTING_AUTH"] = true
77
end
88

9+
def chatops_prefix(prefix = nil)
10+
# We abuse request.env here so that rails will cycle this with each test.
11+
# If we used an instance variable, one would always need to be resetting
12+
# it.
13+
if prefix
14+
request.env["CHATOPS_TESTING_PREFIX"] = prefix
15+
end
16+
request.env["CHATOPS_TESTING_PREFIX"]
17+
end
18+
919
def chatop(method, params = {})
1020
args = params.dup.symbolize_keys
1121
user = args.delete :user
@@ -31,7 +41,8 @@ def chat(message, user, room_id = "123")
3141
matchers = json_response["methods"].map { |name, metadata|
3242
metadata = metadata.dup
3343
metadata["name"] = name
34-
metadata["regex"] = Regexp.new("^#{metadata["regex"]}$", "i")
44+
prefix = chatops_prefix ? "#{chatops_prefix} " : ""
45+
metadata["regex"] = Regexp.new("^#{prefix}#{metadata["regex"]}$", "i")
3546
metadata
3647
}
3748

lib/chatops/controller/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module ChatopsController
2-
VERSION = "3.0.1"
2+
VERSION = "3.0.2"
33
end

spec/lib/chatops/controller_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@ def rails_flexible_post(path, outer_params, jsonrpc_params = nil)
365365
chat "too bad that this message doesn't start with where can i deploy foobar", "bhuga"
366366
}.to raise_error(Chatops::Controller::TestCaseHelpers::NoMatchingCommandRegex)
367367
end
368+
369+
it "allows setting a v2 prefix" do
370+
chatops_prefix "test-prefix"
371+
chat "test-prefix where can i deploy foobar --this-is-sparta", "bhuga"
372+
expect(request.params["chatop"]).to eq "wcid"
373+
end
368374
end
369375
end
370376
end

0 commit comments

Comments
 (0)