Sha256: 674162b91de4bf67e168bb08771b98e6e1b2600af4fa9a5763686d536fb5a43b

Contents?: true

Size: 1.62 KB

Versions: 6

Compression:

Stored size: 1.62 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))

describe "DataMapper::Is" do
  describe ".is" do

    module ::DataMapper

      module Is
        module Example

          def is_example(*args)
            @args = args

            extend DataMapper::Is::Example::ClassMethods
          end

          def is_example_args
            @args
          end

          module ClassMethods
            def example_class_method

            end
          end

        end
      end

      module Model
        include DataMapper::Is::Example
      end # module Model
    end # module DataMapper

    class ::House
      include DataMapper::Resource
    end

    class ::Cabin
      include DataMapper::Resource
    end

    it "should raise error unless it finds the plugin" do
      lambda do
        class ::House
          is :no_plugin_by_this_name
        end
      end.should raise_error(DataMapper::PluginNotFoundError)
    end

    it "should call plugin is_* method" do
      lambda do
        class ::House
          is :example
        end
      end.should_not raise_error
    end

    it "should pass through arguments to plugin is_* method" do
      class ::House
        is :example ,:option1 => :ping, :option2 => :pong
      end

      House.is_example_args.length.should == 1
      House.is_example_args.first[:option2].should == :pong
    end

    it "should not add class_methods before the plugin is activated" do
      Cabin.respond_to?(:example_class_method).should be_false

      class ::Cabin
        is :example
      end

      Cabin.respond_to?(:example_class_method).should be_true

    end

  end
end

Version data entries

6 entries across 6 versions & 4 rubygems

Version Path
datamapper-dm-core-0.9.11 spec/unit/is_spec.rb
rpbertp13-dm-core-0.9.11.1 spec/unit/is_spec.rb
rpbertp13-dm-core-0.9.11.2 spec/unit/is_spec.rb
sam-dm-core-0.9.11 spec/unit/is_spec.rb
dm-core-0.9.11 spec/unit/is_spec.rb
dm-core-0.9.10 spec/unit/is_spec.rb