Giter Site home page Giter Site logo

iron-test's Issues

Example in docs does not work

Description

Executing cargo test with the provided example does not work.

$ cargo test                                                                                                                                                                        โœฑ
   Compiling hello-world v0.0.1 (file:///Users/willweiss/dev/rust/hello-world)
src/main.rs:21:64: 21:70 error: no method named `unwrap` found for type `iron::Response` in the current scope
src/main.rs:21     let result_body = response::extract_body_to_bytes(response.unwrap());
                                                                              ^~~~~~
error: aborting due to previous error
error: Could not compile `hello-world`.

Changing the test to read:

#[test]
fn test_hello_world() {
    let res = request::get("http://localhost:3000/hello",
                                Headers::new(),
                                &HelloWorldHandler).unwrap();
    let result_body = response::extract_body_to_bytes(res);

    assert_eq!(result_body, b"Hello, world!");
}

Fixes the issue as iron_test::response::extract_body_to_bytes takes an argument of type iron::response::Response per the docs.

Thanks in advance!

Environment

darwin 14.5.0
cargo 0.10.0-nightly (10ddd7d 2016-04-08)
iron 0.3.0
iron-test 0.3.0

Build a set of helpers to simplify testing middleware

Currently it's not easily possible to quickly setup a project structure to test against.
For example, to test static_file middleware, I need to make sure that there is a certain directory layout with specific files in it which could be served.

We should build a set of helpers to simplify this (similar to what Cargo does).

The code may look like:

test!(serves_specific_non_default_file {
  let st = Static::new(Path::new(""));
  // mock request and give it to handle method
 // verify response
})

the test! macro will call the setup function and then call the actual test code.

The setup function will be defined once per tests module and will create a directory layout:

project("foo").file("index.html", "<html>hello</html>").build();

I'm currently adapting cargo testing support infrastructure to be used in iron_test.
I actually finished it today, but there was a bug in the code which rm-rf'ed '.' and all my code is gone, I'll need to recreate it tomorrow :)

Docs don't reflect the code

Just wanted to start off by saying I love Iron and all the associated projects, I think they're great ๐Ÿ˜„

I've got a couple quick questions about this repo, just to make sure I'm going insane.

The README show mock requests being built like request::new(<http_method>, <request_target>), while the actual request::new() function looks like it needs three arguments, the third being a reader.

The other functions shown, request::at, request::at_with and all of response, don't seem to exist at all.

So I just wanted to confirm, is this project 'unfinished' at the moment? Or am I entirely missing something?

Once again, thank you for all the work ๐Ÿ˜„

Take Modifier instead of Headers

Feature request: setting request headers is a bit cumbersome right now, it would be nice if the request::* functions took a Modifier instead of a Headers.

API Design

How would we feel about a request API that makes the request for you, broken down by HTTP method?
Something like:

mod request {
  pub fn get<H: Handler>(url: &str, handler: H) -> Response
  pub fn post<H: Handler>(url: &str, handler: H, data: Vec<u8>) -> Response
  // etc
}

It's a little more syntactic sugar than the previously outlined constructor API, but it would also DRY up end user's tests a bit more, and remove some duplicated setup patterns.

I'd being willing to implement either API, just thought of this while I was using this library to test an Iron project.

Borrowing in `extract_body_to_string` and `extract_body_to_bytes`?

I'd like to reuse response in such code:

// .. cut
        let body = response::extract_body_to_string(resp);
        assert_eq!(body, "expected-content");
        assert_eq!(resp.status.unwrap(), Status::Created);
// ..

Is it possible now?

Now it gives:

   |
93 |         let body = response::extract_body_to_string(resp);
   |                                                     ---- value moved here
...
96 |         assert_eq!(resp.status.unwrap(), Status::Created);
   |                    ^^^^^^^^^^^ value used here after move
   |
   = note: move occurs because `resp` has type `iron::Response`, which does not implement the `Copy` trait

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.