Skip to content

Instantly share code, notes, and snippets.

@paulcsmith
Last active November 10, 2017 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulcsmith/d44ac002bd1b7c57dcb8f7217ac499a7 to your computer and use it in GitHub Desktop.
Save paulcsmith/d44ac002bd1b7c57dcb8f7217ac499a7 to your computer and use it in GitHub Desktop.
it "creates new users" do
conn.nested_params :user, name: "Paul", email: "foo@bar.com"
conn.params page: 1
conn.headers "CONTENT_TYPE" => "text/url-form-encoded"
conn.request Users::Create
conn.response.body.should contain "Success!"
end
private def conn
TestConn.build # Build create a new conn or gets the global one
# Hook up after_spec to clean out test connections after each test
end
# Or make your own connection
class AdminConn < TestConn
def sign_in(admin : Admin)
session :user_id, admin.id.to_s
end
end
private def conn
AdminConn.build
end
# Includes the methods directly so it's easier to work with in tests :D
# Also auto includes matchers
private include TestConn
# Or add a new describe that le's you add helpers. Does a private include and includes matchers if present
describe Users::Create, with_helper: TestConn do
it "creates a user" do
nested_params :user, UserBox.params
set_cookie :user_id, AdminBox.create.id.to_s
request Users::Create.route
response.body.should contain "Created!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment