Module: RspecComposeContext

Included in:
RSpec::Core::ExampleGroup
Defined in:
lib/rspec_compose_context.rb,
lib/rspec_compose_context/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#compose_context(*context_names, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/rspec_compose_context.rb', line 4

def compose_context(*context_names, &block)
  m = context_names.inject(self) do |m, (context_name, *args)|
    m.module_eval do
      str = args.map(&:inspect).join(', ')
      str = "(#{str})" unless args.empty?
      context("#{context_name}#{str}") do
        include_context(context_name.to_s, *args)
      end
    end
  end
  m.module_eval &block if block_given?
end