Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSL vs generating ExUnit directly #1

Open
coryodaniel opened this issue Sep 27, 2016 · 4 comments
Open

DSL vs generating ExUnit directly #1

coryodaniel opened this issue Sep 27, 2016 · 4 comments

Comments

@coryodaniel
Copy link
Owner

coryodaniel commented Sep 27, 2016

test "[GET] /kittens (200)", %{swagger: swagger} do
  my_kitten_factory(10)

  swagger
    |> Transaction.build(@mime, :get, "/kittens", 200)
    |> assert_schema 
end

test "Create a kitten", %{swagger: swagger} do
  swagger
    |> Transaction.build(@mime, :post, "/kittens", 201)
    |> put_in([:request, :body], %{name: "Chuancy", type: "cat"})
    |> assert_schema
end

test "Strict kitten making", %{swagger: swagger} do
  swagger
    |> Transaction.build(@mime, :post, "/kittens", 201)
    |> put_in([:request, :body], %{name: "Chuancy", type: "cat"})
    |> assert_match except: [:inserted_at, :updated_at]
end
@jwarlander
Copy link

FWIW, it would be nice if one could approach a flow like this:

  1. Edit pet_store.yml file to add a new API feature
  2. Run 'mix test' and see a new test that fails
  3. Implement code to handle the failing test

I suppose that compiling the spec into tests could be handled by the file watcher if you use Phoenix, but you might just as well be doing "clean" Plug code if you're developing an API :)

How about having an interface similar to ExUnit.DocTest, where you just use a macro to point to the .yml source, and the tests will be generated at compile time when you run mix test?

@coryodaniel
Copy link
Owner Author

I had originally done a DSL (https://github.com/coryodaniel/apocryphal/tree/sly-dsl) and then tore it all up and went with bare ExUnit because it seems more clear (less macros)... Want to peek at the DSL branch and let me know what you think?

@jwarlander
Copy link

Well, for me personally.. I'd just rather not see, or have, any code in my code base that's just generated strictly off of a spec.. The spec is the test code in this case, just like the docs are the tests for DocTests; they don't generate code that's sitting around in your repo.

I don't know where you are on this, though.. it's perfectly fine to have a different opinion, of course ;)

At work we're looking at possibly implementing a couple of small, internal APIs using Elixir. I'd love to play around with running Swagger specs as "acceptance tests" for these things. So I may have more specific ideas / suggestions / questions when we get to that :)

@jwarlander
Copy link

Note, of the two options.. DSL vs. plain ExUnit.. I do like the plain ExUnit version better :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants