Skip to content

Commit

Permalink
Merge pull request #165 from lipanski/one-zero
Browse files Browse the repository at this point in the history
The 1.0 🎈
  • Loading branch information
lipanski authored Mar 12, 2023
2 parents a213df0 + 68c5629 commit 000c435
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 1,961 deletions.
22 changes: 0 additions & 22 deletions .appveyor.yml

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,24 @@ jobs:
- name: Test
run: cargo test --no-default-features

test-windows:
name: Test on Windows
runs-on: windows-latest
steps:
# The Windows runners have autocrlf enabled by default
# which causes failures for some of the line-ending sensitive tests
- name: disable git eol translation
run: git config --global core.autocrlf false
- uses: actions/checkout@v3
- name: Install Rustup using win.rustup.rs
run: |
# Disable the download progress bar which can cause perf issues
$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe
.\rustup-init.exe -y --default-host=x86_64-pc-windows-msvc --default-toolchain=none
del rustup-init.exe
rustup target add x86_64-pc-windows-msvc
shell: powershell
- name: Test
shell: cmd
run: cargo test --no-default-features
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<img src="https://img.shields.io/badge/rust%20version-%3E%3D1.65.0-orange">
<a href="https://crates.io/crates/mockito"><img src="https://img.shields.io/crates/d/mockito"></a>
<a href="https://github.com/lipanski/mockito/actions/workflows/tests.yml/?branch=master"><img src="https://github.com/lipanski/mockito/actions/workflows/tests.yml/badge.svg?branch=master"></a>
<a href="https://ci.appveyor.com/project/lipanski/mockito"><img src="https://ci.appveyor.com/api/projects/status/github/lipanski/mockito?branch=master&svg=true"></a>
</p>
<p align="center"><em>HTTP mocking for Rust!</em></p>
</p>
Expand All @@ -22,10 +21,11 @@ or offline work. Mockito runs a local pool of HTTP servers which create, deliver
- Checks that a mock was called (spy)
- Mocks multiple hosts at the same time
- Exposes sync and async interfaces
- Prints out the last unmatched request in case of errors
- Prints out a colored diff of the last unmatched request in case of errors
- Simple, intuitive API
- An awesome logo


The full documentation is available at <https://docs.rs/mockito>.

Before upgrading, make sure to check out the [changelog](https://github.com/lipanski/mockito/releases).
Expand All @@ -45,7 +45,7 @@ fn test_something() {
let url = server.url();

// Create a mock
let m = server.mock("GET", "/hello")
let mock = server.mock("GET", "/hello")
.with_status(201)
.with_header("content-type", "text/plain")
.with_header("x-api-key", "1234")
Expand All @@ -56,26 +56,30 @@ fn test_something() {
// `content-type: text/plain` header and the body "world".

// You can use `Mock::assert` to verify that your mock was called
m.assert();
mock.assert();
}
```

If `Mock::assert` fails, a colored diff of the last unmatched request is displayed:

![colored-diff.png](https://raw.githubusercontent.com/lipanski/mockito/master/docs/colored-diff.png)

Use **matchers** to handle requests to the same endpoint in a different way:

```rust
#[test]
fn test_something() {
let mut server = mockito::Server::new();

let m1 = server.mock("GET", "/greetings")
server.mock("GET", "/greetings")
.match_header("content-type", "application/json")
.match_body(mockito::Matcher::PartialJsonString(
"{\"greeting\": \"hello\"}".to_string(),
))
.with_body("hello json")
.create();

let m2 = server.mock("GET", "/greetings")
server.mock("GET", "/greetings")
.match_header("content-type", "application/text")
.match_body(mockito::Matcher::Regex("greeting=hello".to_string()))
.with_body("hello text")
Expand Down
Binary file added docs/colored-diff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn compare(expected: &str, actual: &str) -> String {
let z = change.value();
#[cfg(feature = "color")]
#[allow(clippy::unnecessary_to_owned)]
result.push_str(&z.white().on_green().to_string());
result.push_str(&z.black().on_green().to_string());
#[cfg(not(feature = "color"))]
result.push_str(z);
}
Expand Down
95 changes: 0 additions & 95 deletions src/legacy.rs

This file was deleted.

Loading

0 comments on commit 000c435

Please sign in to comment.