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

Extract helpers for expect_equals? #482

Closed
hadley opened this issue Jun 9, 2016 · 5 comments
Closed

Extract helpers for expect_equals? #482

hadley opened this issue Jun 9, 2016 · 5 comments
Labels
expectation 🙀 feature a feature request or enhancement

Comments

@hadley
Copy link
Member

hadley commented Jun 9, 2016

i.e. expect_attr_equal(), expect_element_equal(), expect_slot_equal().

This would let you do quick equality tests in a pipe for subcomponents. If you wanted to test for other things, you'd still need to manually extract

@hadley hadley added expectation 🙀 feature a feature request or enhancement labels Dec 15, 2016
@hadley
Copy link
Member Author

hadley commented Dec 15, 2016

But this isn't particularly elegant because it requires special casing equality tests. You can almost already handle this problem with the tee pipe:

library(testthat)
library(magrittr)

x <- list(
  a = 1,
  b = 2
)

x %>%
  expect_type("list") %T>%
  {expect_equal(.$a, 1)} %T>%
  {expect_equal(.$b, 2)}

But it's not particularly elegant.

Ideally, the tree structure of the testing code would reflect the tree structure of the object.

@hadley
Copy link
Member Author

hadley commented Dec 20, 2016

Or maybe:

x %>%
  expect_type("list") %>%
  tee(
    expect_equal(.$a, 1), 
    expect_equal(.$b, 2)
  )

@krlmlr
Copy link
Member

krlmlr commented Dec 20, 2016

This looks very similar to what ensurer already does.

@krlmlr
Copy link
Member

krlmlr commented Dec 20, 2016

Also, wouldn't we want to use something like

x %>%
  expect_type("list") %>%
  tee(
    expect_equal(.data$a, 1), 
    expect_equal(.data$b, 2)
  )

(and optionally omit .data)?

@hadley
Copy link
Member Author

hadley commented Dec 20, 2016

I don't think so - tee() is very simple to implement if we rely on the existing magrittr semantics.

@hadley hadley closed this as completed Oct 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expectation 🙀 feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants