Class: Funktional::DelegatingShouldBlock

Inherits:
ShouldBlock show all
Defined in:
lib/funktional/context/delegating_should_block.rb

Instance Method Summary collapse

Methods inherited from ShouldBlock

build, #to_test

Constructor Details

#initialize(options, context, &blk) ⇒ DelegatingShouldBlock

Returns a new instance of DelegatingShouldBlock.



4
5
6
7
8
# File 'lib/funktional/context/delegating_should_block.rb', line 4

def initialize(options, context, &blk)
  @should_name = build_should_name(options, &blk)
  @blk = proc { should(options, &blk) }
  @context = context
end

Instance Method Details

#build_should_name(options, &blk) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/funktional/context/delegating_should_block.rb', line 10

def build_should_name(options, &blk)
  case options.keys.first
    when :render
      "render the [#{options[:render]}] template"
    when :render_404
      "render the [#{options[:render_404]}] template with a [404] status code"
    when :redirect_to
      "redirect to the [#{options[:redirect_to]}] url"
    when :assign_new
      "assign a new [#{options[:assign_new]}]"
    when :route, :method
      args = (options.length > 1) ? options : options.values.first
      RouteChecker.build(args, &blk).__test_name
    when :send_email
      "send an email #{options[:send_email].inspect}"
    else
      raise NoMethodError, "#{options.inspect} is not recognised"
  end
end