Skip to content

Commit

Permalink
Add test for default values of options and the help subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Mar 28, 2024
1 parent 3a3efb5 commit 6be1e78
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/rails_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,32 @@ fn arguments_are_directed_to_rails_new() -> Result<(), Box<dyn std::error::Error

Ok(())
}

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

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

let ruby_version = m.get_one::<String>("ruby_version").unwrap();
let rails_version = m.get_one::<String>("rails_version").unwrap();

assert_eq!(ruby_version, "3.2.3");
assert_eq!(rails_version, "7.1.3");

Ok(())
}

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

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

match m.subcommand_name() {
Some("rails-help") => {}
_ => panic!("Expected subcommand 'rails-help'"),
}

Ok(())
}

0 comments on commit 6be1e78

Please sign in to comment.