Sha256: 9d2aa262d0560884dbc5cadbf17b751ae801031ee1612b19895941a485980372

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

require "test_helper"

module Cogy
  class CommandTest < ActionDispatch::IntegrationTest
    include Engine.routes.url_helpers

    setup { @routes = Engine.routes }

    def test_error_response_code
      get "/cogy/cmd/raiser/george"
      assert_equal 500, response.status
    end

    def test_calc_command
      get "/cogy/cmd/calc/george", cog_opt_op: "+", cog_argv_0: 1, cog_argv_1: 2
      assert_equal "Hello george, the answer is: 3", response.body

      get "/cogy/cmd/calc/george", cog_opt_op: "/", cog_argv_0: 10, cog_argv_1: 5
      assert_equal "Hello george, the answer is: 2", response.body
    end

    def test_command_not_found
      get "/cogy/cmd/idontexist/foo"
      assert_equal 404, response.status
    end

    def test_cogy_env
      get "/cogy/cmd/print_env/george", cogy_foo: "bar"
      assert_equal "bar", response.body
    end

    def test_rails_url_helpers
      get "/cogy/cmd/rails_url_helpers/george"
      assert_equal "http://dummy.com/baz /baz", response.body
    end

    def test_invalid_opts_declaration
      exception = assert_raises(ArgumentError) do
        Cogy.on "invalidopts", desc: "foo", opts: { foo: {} } do
          1
        end
      end

      assert_match(/\[:type, :required\]/, exception.message)
    end

    def test_args_ordering
      get "/cogy/cmd/args_order/george", cog_argv_2: 3, cog_argv_1: 2, cog_argv_0: 1
      assert_equal "123", response.body
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cogy-0.2.1 test/integration/command_test.rb
cogy-0.2.0 test/integration/command_test.rb