wax-spec

Spec helpers for the `wax` shard

Wax::Spec

Adds spec helpers for apps using the wax shard. This was pulled out to a separate shard so that apps wouldn't have spec-only dependencies in their production apps.

Installation

  1. Add the dependency to your shard.yml:

    development_dependencies:
      wax-spec:
        github: jgaskins/wax-spec
    
  2. Run shards install

Usage

In your application's spec helpers, load the appropriate helpers provided by wax-spec. For example, in your applications' spec/routes/route_helper.cr, you would do this:

require "../spec_helper" # your app-wide baseline spec helper file
require "wax-spec/route_helper"

Then in your specs you can do this:

describe RouteUnderTest do
  app = app(RouteUnderTest.new)

  context "GET /" do
    it "returns 200 OK" do
      response = app.get "/"

      response.should have_status :ok
      response.should have_html "Hello"
    end
  end

  context "POST /" do
    it "returns 201 CREATED with the correct params" do
      response = app.post "/", form: {
        # other params ...
        _authenticity_token: app.authenticity_token,
      }

      response.should have_status :created
    end

    it "returns 400 BAD REQUEST without the authenticity token" do
      response = app.post "/", form: {
        # non-authenticity-token params
      }

      response.should have_status :bad_request
    end
  end
end

Contributing

  1. Fork it (https://github.com/jgaskins/wax-spec/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

wax-spec

Owner
Statistic
  • 0
  • 0
  • 0
  • 0
  • 2
  • 7 months ago
  • May 1, 2024
License

MIT License

Links
Synced at

Sat, 21 Dec 2024 04:35:21 GMT

Languages