Sha256: 515cc3988b3ddcfc3d0900b54911396ea51b992a295935cf423b9e173c1f0209

Contents?: true

Size: 1.46 KB

Versions: 15

Compression:

Stored size: 1.46 KB

Contents

module RSpecCandy
  module Helpers
    module ItShouldActLike

      def self.included(by)
        by.class_eval do

          # Improves it_should_behave_like in some ways:
          # - It scopes the reused examples so #let und #subject does not bleed into the reusing example groups
          # - It allows to parametrize the reused example group by appending a hash argument.
          #   Every key/value pair in the hash will become a #let variable for the reused example group
          # - You can call it with a block. It will be available to the reused example group as let(:block)
          def it_should_act_like(shared_example_group, environment = {}, &block)
            if Switcher.rspec_version == :rspec2
              warn('"it_should_act_like" is deprecated. Consider using "it_should_behave_like".')
            end

            description = "as #{shared_example_group}"
            description << " (#{environment.inspect})" if environment.present?
            describe description do
              environment.each do |name, value|
                let(name) { value }
              end
              let(:block) { block } if block
              it_should_behave_like(shared_example_group)
            end
          end
        end
      end

      case Switcher.rspec_version
      when :rspec1
        Spec::Example::ExampleGroupMethods.send(:include, self)
      when :rspec2
        RSpec::Core::ExampleGroup.singleton_class.send(:include, self)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rspec_candy-0.3.0 lib/rspec_candy/helpers/it_should_act_like.rb
rspec_candy-0.2.10 lib/rspec_candy/helpers/it_should_act_like.rb
rspec_candy-0.2.9 lib/rspec_candy/helpers/it_should_act_like.rb
rspec_candy-0.2.8 lib/rspec_candy/helpers/it_should_act_like.rb
rspec_candy-0.2.7 lib/rspec_candy/helpers/it_should_act_like.rb
rspec_candy-0.2.6 lib/rspec_candy/helpers/it_should_act_like.rb
rspec_candy-0.2.5 lib/rspec_candy/helpers/it_should_act_like.rb
rspec_candy-0.2.4 lib/rspec_candy/helpers/it_should_act_like.rb
rspec_candy-0.2.3 lib/rspec_candy/helpers/it_should_act_like.rb
rspec_candy-0.2.2 lib/rspec_candy/helpers/it_should_act_like.rb
rspec_candy-0.2.1 lib/rspec_candy/helpers/it_should_act_like.rb
rspec_candy-0.2.0 lib/rspec_candy/helpers/it_should_act_like.rb
rspec_candy-0.1.2 lib/rspec_candy/helpers/it_should_act_like.rb
rspec_candy-0.1.1 lib/rspec_candy/helpers/it_should_act_like.rb
rspec_candy-0.1.0 lib/rspec_candy/helpers/it_should_act_like.rb