Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nercury/specker-rs
Testing utility that simplifies file matching against bunch of templates.
https://github.com/nercury/specker-rs
Last synced: about 2 months ago
JSON representation
Testing utility that simplifies file matching against bunch of templates.
- Host: GitHub
- URL: https://github.com/nercury/specker-rs
- Owner: Nercury
- License: other
- Created: 2017-02-12T17:45:43.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-08T10:15:15.000Z (almost 7 years ago)
- Last Synced: 2024-11-20T19:41:54.076Z (about 2 months ago)
- Language: Rust
- Size: 93.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
## Specker
[![Build Status](https://travis-ci.org/Nercury/specker-rs.svg?branch=master)](https://travis-ci.org/Nercury/specker-rs)
Checks if any number of files match some specification.
Designed for testing file generation.Let's say we have this specification:
```
## file: output/index.html
....
## file: output/style.css
..
body {
..
}
..
```Specker can check if there is a file named `output/index.html` containing
`` in some line, as well as file `output/style.css`
containing `body {` and `}` lines. Symbol `..` matches any number of
lines.If there is a match error, specker can print a nice message like:
```
1 |
| ^^^^^^
| Expected "", found ""
```It also has iterators to run many such specification tests
in bulk.Example code that iterates the "spec" dir, collects all "txt" specifications
and checks them:```rust
extern crate specker;use std::fs;
use std::env;
use std::path::PathBuf;
use std::collections::HashMap;#[test]
fn check_specifications() {
let src_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());for maybe_spec in specker::walk_spec_dir(&spec_dir, "txt", specker::Options {
skip_lines: "..",
marker: "##",
var_start: "${",
var_end: "}",
}) {
let spec_path = maybe_spec.unwrap_or_else(|e| {
// print nicely formatted error
panic!("\n{}", specker::display_error(&e));
});// go over spec items and check if file contents match
for (item, input_file_name) in spec_path.spec.iter()
.filter_map(
|item| item.get_param("file")
.map(|param_value| (item, param_value))
)
{
let path = spec_dir.join(input_file_name);
let mut file = fs::File::open(&path)
.expect(&format!("failed to open file {:?}", &path));if let Err(e) = item.match_contents(&mut file, &HashMap::new()) {
// print nicely formatted error
println!("{}", specker::display_error_for_file(&path, &e));
// print one-liner error
panic!("{}", e);
}
}
}
}
```## License
Licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in the work by you, as defined in the Apache-2.0
license, shall be dual licensed as above, without any additional terms or
conditions.