Skip to content

Commit

Permalink
Modularize step defs
Browse files Browse the repository at this point in the history
  • Loading branch information
ivnsch committed Dec 7, 2021
1 parent 53e9810 commit 9359029
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ native = ["algonaut_client/native"]
rustls = ["algonaut_client/rustls"]

[[test]]
name = "cucumber"
name = "features_runner"
harness = false # Allows Cucumber to print output instead of libtest
14 changes: 14 additions & 0 deletions tests/features_runner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use cucumber::WorldInit;
use step_defs::integration;

mod step_defs;

#[tokio::main]
async fn main() {
integration::algod::World::run(integration_path("algod")).await;
integration::abi::World::run(integration_path("abi")).await;
}

fn integration_path(feature_name: &str) -> String {
format!("tests/features/integration/{}.feature", feature_name)
}
29 changes: 29 additions & 0 deletions tests/step_defs/integration/abi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use algonaut::algod::v2::Algod;
use algonaut::algod::AlgodBuilder;
use async_trait::async_trait;
use cucumber::{given, WorldInit};
use std::convert::Infallible;

#[derive(Default, Debug, WorldInit)]
pub struct World {
algod: Option<Algod>,
}

#[async_trait(?Send)]
impl cucumber::World for World {
type Error = Infallible;

async fn new() -> Result<Self, Self::Error> {
Ok(Self::default())
}
}

#[given(expr = "an algod v2 client")]
async fn an_algod_v2_client(w: &mut World) {
let algod = AlgodBuilder::new()
.bind("http://localhost:60000")
.auth("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
.build_v2()
.unwrap();
w.algod = Some(algod)
}
5 changes: 0 additions & 5 deletions tests/cucumber.rs → tests/step_defs/integration/algod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,3 @@ async fn i_can_get_the_block_info(w: &mut World) {
let last_round = w.last_round.unwrap();
algod_client.block(Round(last_round)).await.unwrap();
}

#[tokio::main]
async fn main() {
World::run("tests/features/integration").await;
}
2 changes: 2 additions & 0 deletions tests/step_defs/integration/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod abi;
pub mod algod;
1 change: 1 addition & 0 deletions tests/step_defs/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod integration;

0 comments on commit 9359029

Please sign in to comment.