Skip to content

Commit

Permalink
Follow Rust best practives by moving tests into a module
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Mar 28, 2024
1 parent 57af0ab commit dd51729
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/rails_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@ pub struct Cli {
pub rails_version: String,
}

#[test]
fn verify_cli() {
use clap::CommandFactory;
Cli::command().debug_assert()
}
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn verify_cli() {
use clap::CommandFactory;

Cli::command().debug_assert()
}

#[test]
fn arguments_are_directed_to_rails_new() -> Result<(), Box<dyn std::error::Error>> {
use clap::CommandFactory;
#[test]
fn arguments_are_directed_to_rails_new() -> Result<(), Box<dyn std::error::Error>> {
use clap::CommandFactory;

let m = Cli::command().get_matches_from(vec!["rails-new", "my_app", "--main"]);
let m = Cli::command().get_matches_from(vec!["rails-new", "my_app", "--main"]);

let trail: Vec<_> = m.get_many::<String>("args").unwrap().collect();
let trail: Vec<_> = m.get_many::<String>("args").unwrap().collect();

assert_eq!(trail, &["my_app", "--main"]);
assert_eq!(trail, &["my_app", "--main"]);

Ok(())
Ok(())
}
}

0 comments on commit dd51729

Please sign in to comment.