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

Email steps: I can't check for a specific sentence within the body if it doesn't start a new line #155

Closed
FLeinzi opened this issue Nov 18, 2020 · 1 comment

Comments

@FLeinzi
Copy link
Contributor

FLeinzi commented Nov 18, 2020

Given we have this email:

From: [email protected]
To: [email protected]
Subject: Lorem ipsum

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.

Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. VERY IMPORTANT SENTENCE. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.

With the refactored email step an email should have been sent with: I can't test for "VERY IMPORTANT SENTENCE" anymore.

Maybe it's possible to adapt the expected_body_regex in the MailFinder to also allow a wildcard at the beginning, like this:

Then an email should have been sent with:
  """
  From: [email protected]
  To: [email protected]
  Subject: Lorem ipsum

  Lorem ipsum dolor sit amet, consetetur sadipscing elitr*

  *VERY IMPORTANT SENTENCE*

  Ut wisi enim ad minim veniam*
  """

My suggestion is to add expected.gsub! '\n\*', '\n.*' to the method

def expected_body_regex(expected_body)
  # To stay backwards-compatible, this will only check whether an email
  # starts with the expected body.
  expected = '\A\n' + Regexp.quote(expected_body.strip) + '\n\Z'
  expected.gsub! '\n\*\n', '\n[\s\S]*\n'
  expected.gsub! '\*\n', '.*\n'

  expected.gsub! '\A\n', '\A'
  expected.gsub! '\n\Z', '' # Change '' to '\Z' to force that the whole body matches

  Regexp.new(expected)
end

Do you see any problems with that?

@FLeinzi
Copy link
Contributor Author

FLeinzi commented Nov 18, 2020

Fixed in version 2.99.3 and 3.0.2

@FLeinzi FLeinzi closed this as completed Nov 18, 2020
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

No branches or pull requests

1 participant