Sha256: 7482608fda427fcf368eee7a9103e3d017b78de2a3d3d8bc91ceba3905cfdc75

Contents?: true

Size: 1.6 KB

Versions: 17

Compression:

Stored size: 1.6 KB

Contents

require File.expand_path("spec_helper", File.dirname(__FILE__))

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 "

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

    body('/hello').should == '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.should == '1'
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
roda-2.2.0 spec/plugin_spec.rb
roda-2.1.0 spec/plugin_spec.rb
roda-2.0.0 spec/plugin_spec.rb
roda-1.3.0 spec/plugin_spec.rb
roda-1.2.0 spec/plugin_spec.rb
roda-1.1.0 spec/plugin_spec.rb
roda-cj-1.0.5 spec/plugin_spec.rb
roda-cj-1.0.4 spec/plugin_spec.rb
roda-cj-1.0.3 spec/plugin_spec.rb
roda-cj-1.0.2 spec/plugin_spec.rb
roda-cj-1.0.1 spec/plugin_spec.rb
roda-cj-1.0.0 spec/plugin_spec.rb
roda-1.0.0 spec/plugin_spec.rb
roda-cj-0.9.6 spec/plugin_spec.rb
roda-cj-0.9.5 spec/plugin_spec.rb
roda-cj-0.9.4 spec/plugin_spec.rb
roda-cj-0.9.3 spec/plugin_spec.rb