-
Is there a standard way to run cucumber tests against a database? Specifically, I am using #[sqlx::test]
async fn basic_test(pool: PgPool) -> sqlx::Result<()> {
let mut conn = pool.acquire().await?;
sqlx::query("SELECT * FROM foo")
.fetch_one(&mut conn)
.await?;
assert_eq!(foo.get::<String>("bar"), "foobar!");
Ok(())
} To use this in cucumber, I think I would have to pass the pool or a connection into the World object, but I don't see how to do that. I tried doing this: struct AnimalWorld {
pool: Option<Arc<PgPool>>
}
#[sqlx::test]
async fn main(pool: PgPool) -> Result<()> {
AnimalWorld::cucumber()
.fail_on_skipped()
.before(|_feature, _rule, _scenario, world| {
Box::pin(async {
world.pool = Some(Arc::new(pool.clone()));
})
})
.run("features")
.await;
Ok(())
} ...but that gives me a lifetime error because |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@pbevin it looks like |
Beta Was this translation helpful? Give feedback.
@pbevin alternatively the book also describes a way to use custom
World
constructors that actually can be async: