Sha256: 4aad54eb2ffb110a53d36db076ec6ceb3e204544f8b67acf3ee737b5a1f05aeb

Contents?: true

Size: 1.58 KB

Versions: 30

Compression:

Stored size: 1.58 KB

Contents

require_relative "spec_helper"

describe "plugins" do
  it "should be able to override class, instance, response, and request methods, and execute configure method" do
    c = Module.new do
      self::ClassMethods = Module.new do
        def fix(str)
          opts[:prefix] + str.strip
        end
      end
      self::InstanceMethods = Module.new do
        def fix(str)
          super("a" + str)
        end
      end
      self::RequestMethods = Module.new do
        def hello(&block)
          on self.class.hello, &block
        end
      end
      self::RequestClassMethods = Module.new do
        def hello(&block)
          'hello'
        end
      end
      self::ResponseMethods = Module.new do
        def foobar
          self.class.foobar
        end
      end
      self::ResponseClassMethods = Module.new do
        def foobar
          "Default   "
        end
      end

      def self.load_dependencies(mod, prefix)
        mod.send(:include, Module.new do
          def fix(str)
            self.class.fix(str)
          end
        end)
      end

      def self.configure(mod, prefix)
        mod.opts[:prefix] = prefix
      end
    end

    app(:bare) do
      plugin(c, "Foo ").must_be_nil

      route do |r|
        r.hello do
          fix(response.foobar)
        end
      end
    end

    body('/hello').must_equal 'Foo aDefault'
  end

  it "should support registering plugins and loading them by symbol" do
    Roda::RodaPlugins.register_plugin(:foo, Module.new{module self::InstanceMethods; def a; '1' end end})
    app(:foo) do
      a
    end

    body.must_equal '1'
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
roda-3.28.0 spec/plugin_spec.rb
roda-3.27.0 spec/plugin_spec.rb
roda-3.26.0 spec/plugin_spec.rb
roda-3.25.0 spec/plugin_spec.rb
roda-3.24.0 spec/plugin_spec.rb
roda-3.23.0 spec/plugin_spec.rb
roda-3.22.0 spec/plugin_spec.rb
roda-3.21.0 spec/plugin_spec.rb
roda-3.20.0 spec/plugin_spec.rb
roda-3.19.0 spec/plugin_spec.rb
roda-3.18.0 spec/plugin_spec.rb
roda-3.17.0 spec/plugin_spec.rb
roda-3.16.0 spec/plugin_spec.rb
roda-3.15.0 spec/plugin_spec.rb
roda-3.14.1 spec/plugin_spec.rb
roda-3.14.0 spec/plugin_spec.rb
roda-3.13.0 spec/plugin_spec.rb
roda-3.12.0 spec/plugin_spec.rb
roda-3.11.0 spec/plugin_spec.rb
roda-3.10.0 spec/plugin_spec.rb