Module: RSpecStepwise::ClassMethods

Defined in:
lib/two-step/stepwise.rb

Instance Method Summary collapse

Instance Method Details

#after(*args, &block) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/two-step/stepwise.rb', line 108

def after(*args, &block)
  if args.first == :step
    args.shift
    options = (args)
    hooks[:after][:step] ||= []
    return (hooks[:after][:step].unshift build_after_hook(options, &block))
  end
  if args.first == :each
    puts "after blocks declared for steps are always treated as :all scope"
  end
  super
end

#around(*args, &block) ⇒ Object



121
122
123
124
125
126
# File 'lib/two-step/stepwise.rb', line 121

def around(*args, &block)
  if args.first == :each
    puts "around :each blocks declared for steps are treated as :all scope"
  end
  super
end

#before(*args, &block) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/two-step/stepwise.rb', line 96

def before(*args, &block)
  if args.first == :step
    args.shift
    options = (args)
    return ((hooks[:before][:step] ||= []) << build_before_hook(options, &block))
  end
  if args.first == :each
    puts "before blocks declared for steps are always treated as :all scope"
  end
  super
end

#build_after_hook(options, &block) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/two-step/stepwise.rb', line 87

def build_after_hook(options, &block)
  if defined? RSpec::Core::Hooks::AfterHookExtension
    block.extend(RSpec::Core::Hooks::AfterHookExtension).with(options)
  else
    RSpec::Core::Hooks::AfterHook.new(block, options)
  end
end

#build_before_hook(options, &block) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/two-step/stepwise.rb', line 79

def build_before_hook(options, &block)
  if defined? RSpec::Core::Hooks::BeforeHookExtension
    block.extend(RSpec::Core::Hooks::BeforeHookExtension).with(options)
  else
    RSpec::Core::Hooks::BeforeHook.new(block, options)
  end
end

#example_synonym(named, desc = nil, *args, &block) ⇒ Object



128
129
130
131
132
133
# File 'lib/two-step/stepwise.rb', line 128

def example_synonym(named, desc=nil, *args, &block)
  unless desc.nil?
    desc = [named, desc].join(" ")
  end
  it(desc, *args, &block)
end

#next(*args, &block) ⇒ Object



137
# File 'lib/two-step/stepwise.rb', line 137

def next(*args, &block); example_synonym("next", *args, &block); end

#perform_steps(name, *args, &customization_block) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/two-step/stepwise.rb', line 164

def perform_steps(name, *args, &customization_block)
  shared_block = nil
  if world.respond_to? :shared_example_groups
    shared_block = world.shared_example_groups[name]
  else
    shared_block = shared_example_groups[name]
  end
  raise "Could not find shared example group named #{name.inspect}" unless shared_block

  module_eval_with_args(*args, &shared_block)
  module_eval(&customization_block) if customization_block
end

#run_after_step(example) ⇒ Object



158
159
160
161
162
# File 'lib/two-step/stepwise.rb', line 158

def run_after_step(example)
  run_step(example, :after) do |groups|
    groups.reverse
  end
end

#run_before_step(example) ⇒ Object



154
155
156
# File 'lib/two-step/stepwise.rb', line 154

def run_before_step(example)
  run_step(example, :before)
end

#run_examples(reporter) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/two-step/stepwise.rb', line 177

def run_examples(reporter)
  whole_list_example = WholeListExample.new(self, "step list", {})

  instance = new
  set_ivars(instance, before_all_ivars)
  instance.example = whole_list_example
  instance.reporter = reporter

  result = suspend_transactional_fixtures do
    whole_list_example.run(instance, reporter)
  end

  unless whole_list_example.exception.nil?
    RSpec.wants_to_quit = true if fail_fast?
    fail_filtered_examples(whole_list_example.exception, reporter)
  end

  result
end

#run_step(example, hook, &sorting) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/two-step/stepwise.rb', line 140

def run_step(example, hook, &sorting)
  groups = if respond_to?(:parent_groups)
                    parent_groups
                  else
                    ancestors
                  end

  if block_given?
    groups = yield groups
  end

  RSpec::Core::Hooks::HookCollection.new(groups.map {|a| a.hooks[hook][:step]}.flatten.compact).for(example).run
end

#step(*args, &block) ⇒ Object



138
# File 'lib/two-step/stepwise.rb', line 138

def step(*args, &block); example_synonym("step", *args, &block); end

#suspend_transactional_fixturesObject

This is hacky and needs a more general solution Something like cloning the current conf and having RSpec::Stepwise::config ?



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/two-step/stepwise.rb', line 64

def suspend_transactional_fixtures
  if self.respond_to? :use_transactional_fixtures
    begin
      old_val = self.use_transactional_fixtures
      self.use_transactional_fixtures = false

      yield
    ensure
      self.use_transactional_fixtures = old_val
    end
  else
    yield
  end
end

#then(*args, &block) ⇒ Object



136
# File 'lib/two-step/stepwise.rb', line 136

def then(*args, &block); example_synonym("then", *args, &block); end

#when(*args, &block) ⇒ Object



135
# File 'lib/two-step/stepwise.rb', line 135

def when(*args, &block); example_synonym("when", *args, &block); end