Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix keyword arguments not being passed when using step annotation #550

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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