cucumber-rs / cucumber

Cucumber testing framework for Rust. Fully native, no external test runners or dependencies.
https://cucumber-rs.github.io/cucumber/main
Apache License 2.0
579 stars 70 forks source link

Steps definitions need to be in the same file as the World from rust >= 1.67 #271

Closed beoboo closed 1 year ago

beoboo commented 1 year ago

When I run a very minimal example with the following setup with

Digging further, it seems like it can find the steps definitions if they are in the same file as the AnimalWorld context file or in the lib file, but not if they are put in a separate file (even if it's a pub mod or with pub use).

tyranron commented 1 year ago

@ilslv seems to be something inventory-related.

ilslv commented 1 year ago

@beoboo I've tried your setup locally on 1.66, 1.67 and 1.68 and in every case all test functions wired up properly. There is open issue in inventory about multi-crate behaviour, I think you are having the same problem. You can try adding extern crate cucumber_test; in uat.rs as suggested there, but alternatively you can restructure your project from

src/_
    | lib.rs
    | context.rs
    | steps.rs
tests/
    | uat.rs
    |_features/
    |   | *
Cargo.toml

to

src/_
    | lib.rs         // Only logic to test here. 
tests/
    | uat.rs
    | context.rs
    | steps.rs
    |_features/
    |   | *
Cargo.toml

We expect users of this crate to have all tested logic in /src/lib.rs//src/main.rs and all testing stuff in /tests/* directory. The similar issue was addressed here.

I'm closing this issue, but feel free to reopen in case there are unanswered questions you have.


@tyranron as this isn't the first time this issue is brought up, maybe we should create a separate git repository with basic starter project?

beoboo commented 1 year ago

Thanks @ilslv, moving code inside tests did solve the issue indeed, and it's now working for Rust 1.68.2.

tyranron commented 1 year ago

@tyranron as this isn't the first time this issue is brought up, maybe we should create a separate git repository with basic starter project?

Let's postpone this for a while, till happens more times.