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

Customizable description #41

Merged
merged 3 commits into from
Jun 13, 2017

Conversation

aliaksandr-martsinovich
Copy link
Contributor

This PR allows users to specify custom descriptions using magic argument :case_name

describe "Custom names for regular syntax" do
  where(:case_name, :a, :b, :answer) do
    [
        ["positive integers",  6,  2,  8],
        ["negative integers", -1, -2, -3],
        [   "mixed integers", -5,  3, -2],
    ]
  end

  with_them do
    it "should do additions" do
      expect(a + b).to eq answer
  end
end

# Output:
# Custom test case name
#   positive integers
#     should do additions
#   negative integers
#     should do additions
#   mixed integers
#     should do additions

For hash syntax you can specify a lambda that would be fed with other arguments:

describe "Custom naming for hash syntax" do
  where(case_names: ->(a, b, c){"#{a} + #{b} + #{c}"}, a: [1, 3], b: [5, 7, 9], c: [2, 4])

  with_them do
    it "sum is even" do
      expect(a + b + c).to be_even
    end
  end
end
# Output:
# when hash arguments
#   1 + 5 + 2
#     sum is even
#   1 + 5 + 4
#     sum is even
#   1 + 7 + 2
#     sum is even
#   ...

Maybe not the most elegant solution, but I've been using it for a while and it's better then nothing.

:case_name -> "name" for regular syntax
:case_names -> lambda for hash syntax
context "when regular arguments" do
where(:case_name, :a, :b, :answer) do
[
["positive integers", 6, 2, 8],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix to 2 spaces indent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here and in readme

@sue445
Copy link
Collaborator

sue445 commented Jun 12, 2017

@aliaksandr-martsinovich LGTM

@joker1007 How do you think?

@joker1007
Copy link
Collaborator

LGTM too.
Thanks !!

@joker1007 joker1007 merged commit 11566ee into tomykaira:master Jun 13, 2017
@aliaksandr-martsinovich aliaksandr-martsinovich deleted the case-name-logging branch June 13, 2017 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants