Skip to content
This repository
tree: 063445fb7f
Fetching contributors…

Cannot retrieve contributors at this time

file 61 lines (48 sloc) 1.349 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
require 'spec_helper'

module Jimson
  describe Handler do

    class FooHandler
      extend Jimson::Handler

      jimson_expose :to_s, :bye

      jimson_exclude :hi, :bye

      def hi
        'hi'
      end

      def bye
        'bye'
      end

      def to_s
        'foo'
      end

      def so_exposed
        "I'm so exposed!"
      end
    end

    let(:foo) { FooHandler.new }

    describe "#jimson_expose" do
      it "exposes a method even if it was defined on Object" do
        foo.class.jimson_exposed_methods.should include('to_s')
      end
    end

    describe "#jimson_exclude" do
      context "when a method was not explicitly exposed" do
        it "excludes the method" do
          foo.class.jimson_exposed_methods.should_not include('hi')
        end
      end
      context "when a method was explicitly exposed" do
        it "does not exclude the method" do
          foo.class.jimson_exposed_methods.should include('bye')
        end
      end
    end

    describe "#jimson_exposed_methods" do
      it "doesn't include methods defined on Object" do
        foo.class.jimson_exposed_methods.should_not include('object_id')
      end
      it "includes methods defined on the extending class but not on Object" do
        foo.class.jimson_exposed_methods.should include('so_exposed')
      end
    end

  end
end
Something went wrong with that request. Please try again.