Skip to content

Commit 3be4969

Browse files
committed
Tagged hooks for JRuby. Fixes #467.
1 parent 8eaab0a commit 3be4969

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

History.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## [Git master](https://github.com/cucumber/cucumber-jvm/compare/v1.1.3...master) (not released)
22

3+
* [JRuby] Tagged hooks for JRuby ([#467](https://github.com/cucumber/cucumber-jvm/issues/467) Aslak Hellesøy)
34
* [Spring] Implementation based on SpringJunit4ClassRunner. ([#448](https://github.com/cucumber/cucumber-jvm/issues/448), [#489](https://github.com/cucumber/cucumber-jvm/pull/489) Pedro Antonio Souza Viegas)
45
* [Core] Bugfix: Generated regex for ? character is incorrect. ([#494](https://github.com/cucumber/cucumber-jvm/issues/494) Aslak Hellesøy)
56
* [Core] Improve readability with unanchored regular expressions ([#485](https://github.com/cucumber/cucumber-jvm/pull/485), [#466](https://github.com/cucumber/cucumber-jvm/issues/466) Anton)

jruby/src/main/java/cucumber/runtime/jruby/JRubyBackend.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ public void registerStepdef(RubyObject stepdefRunner) {
123123
glue.addStepDefinition(new JRubyStepDefinition(this, stepdefRunner));
124124
}
125125

126-
public void registerBeforeHook(RubyObject procRunner) {
127-
glue.addBeforeHook(new JRubyHookDefinition(this, new String[0], procRunner));
126+
public void registerBeforeHook(RubyObject procRunner, String[] tagExpressions) {
127+
glue.addBeforeHook(new JRubyHookDefinition(this, tagExpressions, procRunner));
128128
}
129129

130-
public void registerAfterHook(RubyObject procRunner) {
131-
glue.addAfterHook(new JRubyHookDefinition(this, new String[0], procRunner));
130+
public void registerAfterHook(RubyObject procRunner, String[] tagExpressions) {
131+
glue.addAfterHook(new JRubyHookDefinition(this, tagExpressions, procRunner));
132132
}
133133

134134
public void registerWorldBlock(RubyObject procRunner) {

jruby/src/main/resources/cucumber/runtime/jruby/dsl.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ def pattern
9393
end
9494

9595
module Dsl
96-
def Before(&proc)
97-
$backend.registerBeforeHook(HookRunner.new(proc))
96+
def Before(*tag_expressions, &proc)
97+
$backend.registerBeforeHook(HookRunner.new(proc), tag_expressions)
9898
end
9999

100-
def After(&proc)
101-
$backend.registerAfterHook(HookRunner.new(proc))
100+
def After(*tag_expressions, &proc)
101+
$backend.registerAfterHook(HookRunner.new(proc), tag_expressions)
102102
end
103103

104104
def World(*modules_or_proc)

jruby/src/test/resources/cucumber/runtime/jruby/test/cukes.feature

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
Feature: Cukes
22

3+
@tag
4+
Scenario: running tagged hook
5+
Then tagged hook ran
6+
7+
Scenario: not running tagged hook
8+
Then tagged hook didn't run
9+
310
Scenario: in the belly
411
Given I have 4 "cukes" in my belly
512
Then I am "happy"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'cucumber/api/jruby/en'
2+
3+
Before('@tag') do
4+
@tagged_hook_ran = true
5+
end
6+
7+
Then /^tagged hook ran$/ do
8+
raise "Tagged hook didn't run when it should" unless @tagged_hook_ran
9+
end
10+
11+
Then /^tagged hook didn't run$/ do
12+
raise "Tagged hook ran when it shouldn't" if @tagged_hook_ran
13+
end

0 commit comments

Comments
 (0)