Skip to content

Commit

Permalink
Fix keyword arguments not being passed when using step annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
andrcuns committed May 6, 2024
1 parent 5d5ef27 commit 996dbac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def singleton_method_added(method_name)
step_name = @allure_step.empty? ? method_name.to_s : @allure_step
@allure_step = nil

define_singleton_method(method_name) do |*args, &block|
Allure.run_step(step_name) { original_method.call(*args, &block) }
define_singleton_method(method_name) do |*args, **kwargs, &block|
Allure.run_step(step_name) { original_method.call(*args, **kwargs, &block) }
end
end

Expand All @@ -32,8 +32,8 @@ def method_added(method_name)
step_name = @allure_step.empty? ? method_name.to_s : @allure_step
@allure_step = nil

define_method(method_name) do |*args, &block|
Allure.run_step(step_name) { original_method.bind_call(self, *args, &block) }
define_method(method_name) do |*args, **kwargs, &block|
Allure.run_step(step_name) { original_method.bind_call(self, *args, **kwargs, &block) }
end
end
end
23 changes: 13 additions & 10 deletions allure-ruby-commons/spec/unit/step_annotation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,40 @@ class TestHelper
extend AllureStepAnnotation

step("Singleton step")
def self.class_method; end
def self.class_method(arg)
"class_method: #{arg}"
end

step("Standard step")
def standard_method; end
def standard_method(keyword_arg:)
"standard_method: #{keyword_arg}"
end

step
def default_name_method; end
def default_name_method
"default_name"
end
end

describe AllureStepAnnotation do
let(:test_helper) { TestHelper.new }

before do
allow(Allure).to receive(:run_step)
allow(Allure).to receive(:run_step).and_yield
end

it "Creates step from singleton method" do
TestHelper.class_method

expect(TestHelper.class_method("test")).to eq("class_method: test")
expect(Allure).to have_received(:run_step).with("Singleton step")
end

it "Creates step from instance method" do
test_helper.standard_method

expect(test_helper.standard_method(keyword_arg: "value")).to eq("standard_method: value")
expect(Allure).to have_received(:run_step).with("Standard step")
end

it "Creates step with default method name" do
test_helper.default_name_method

expect(test_helper.default_name_method).to eq("default_name")
expect(Allure).to have_received(:run_step).with("default_name_method")
end
end

0 comments on commit 996dbac

Please sign in to comment.