Module: RSpecStepwise::ClassMethods
- Defined in:
- lib/rspec-steps/stepwise.rb
Instance Method Summary collapse
- #_metadata_from_args(args) ⇒ Object
- #after(*args, &block) ⇒ Object
- #around(*args, &block) ⇒ Object
- #before(*args, &block) ⇒ Object
- #build_after_hook(options, &block) ⇒ Object
- #build_before_hook(options, &block) ⇒ Object
- #example_synonym(named, desc = nil, *args, &block) ⇒ Object
- #next(*args, &block) ⇒ Object
- #perform_steps(name, *args, &customization_block) ⇒ Object
- #run_after_step(example) ⇒ Object
- #run_before_step(example) ⇒ Object
- #run_examples(reporter) ⇒ Object
- #run_step(example, hook, &sorting) ⇒ Object
- #step(*args, &block) ⇒ Object
-
#suspend_transactional_fixtures ⇒ Object
This is hacky and needs a more general solution Something like cloning the current conf and having RSpec::Stepwise::config ?.
- #then(*args, &block) ⇒ Object
- #when(*args, &block) ⇒ Object
Instance Method Details
#_metadata_from_args(args) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/rspec-steps/stepwise.rb', line 115 def (args) if RSpec::Core::Metadata.respond_to?(:build_hash_from) RSpec::Core::Metadata.build_hash_from(args) else (args) end end |
#after(*args, &block) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/rspec-steps/stepwise.rb', line 135 def after(*args, &block) if args.first == :step args.shift = (args) hooks[:after][:step] ||= [] return (hooks[:after][:step].unshift build_after_hook(, &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
148 149 150 151 152 153 |
# File 'lib/rspec-steps/stepwise.rb', line 148 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
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/rspec-steps/stepwise.rb', line 123 def before(*args, &block) if args.first == :step args.shift = (args) return ((hooks[:before][:step] ||= []) << build_before_hook(, &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
107 108 109 110 111 112 113 |
# File 'lib/rspec-steps/stepwise.rb', line 107 def build_after_hook(, &block) if defined? RSpec::Core::Hooks::AfterHookExtension block.extend(RSpec::Core::Hooks::AfterHookExtension).with() else RSpec::Core::Hooks::AfterHook.new(block, ) end end |
#build_before_hook(options, &block) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/rspec-steps/stepwise.rb', line 99 def build_before_hook(, &block) if defined? RSpec::Core::Hooks::BeforeHookExtension block.extend(RSpec::Core::Hooks::BeforeHookExtension).with() else RSpec::Core::Hooks::BeforeHook.new(block, ) end end |
#example_synonym(named, desc = nil, *args, &block) ⇒ Object
155 156 157 158 159 160 |
# File 'lib/rspec-steps/stepwise.rb', line 155 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
164 |
# File 'lib/rspec-steps/stepwise.rb', line 164 def next(*args, &block); example_synonym("next", *args, &block); end |
#perform_steps(name, *args, &customization_block) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/rspec-steps/stepwise.rb', line 191 def perform_steps(name, *args, &customization_block) shared_block = nil if respond_to?(:world) and world.respond_to? :shared_example_groups shared_block = world.shared_example_groups[name] else if respond_to?(:shared_example_groups) shared_block = shared_example_groups[name] else shared_block = RSpec.world.shared_example_group_registry.find(parent_groups, name) end end raise "Could not find shared example group named #{name.inspect}" unless shared_block if respond_to? :module_exec module_exec(*args, &shared_block) module_exec(&customization_block) if customization_block else module_eval_with_args(*args, &shared_block) module_eval(&customization_block) if customization_block end end |
#run_after_step(example) ⇒ Object
185 186 187 188 189 |
# File 'lib/rspec-steps/stepwise.rb', line 185 def run_after_step(example) run_step(example, :after) do |groups| groups.reverse end end |
#run_before_step(example) ⇒ Object
181 182 183 |
# File 'lib/rspec-steps/stepwise.rb', line 181 def run_before_step(example) run_step(example, :before) end |
#run_examples(reporter) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/rspec-steps/stepwise.rb', line 213 def run_examples(reporter) whole_list_example = WholeListExample.new(self, "step list", {}) instance = new if respond_to? :before_context_ivars set_ivars(instance, before_context_ivars) else set_ivars(instance, before_all_ivars) end instance.example = whole_list_example if respond_to? :example= instance.reporter = reporter if respond_to? :reporter= result = suspend_transactional_fixtures do whole_list_example.run(instance, reporter) end unless whole_list_example.exception.nil? if fail_fast? if RSpec.respond_to? :wants_to_quit= RSpec.wants_to_quit = true else RSpec.world.wants_to_quit = true end end if respond_to? :fail_filtered_examples fail_filtered_examples(whole_list_example.exception, reporter) else ex = whole_list_example.exception for_filtered_examples(reporter) {|example| example.fail_with_exception(reporter, ex) } end end result end |
#run_step(example, hook, &sorting) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/rspec-steps/stepwise.rb', line 167 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
165 |
# File 'lib/rspec-steps/stepwise.rb', line 165 def step(*args, &block); example_synonym("step", *args, &block); end |
#suspend_transactional_fixtures ⇒ Object
This is hacky and needs a more general solution Something like cloning the current conf and having RSpec::Stepwise::config ?
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rspec-steps/stepwise.rb', line 84 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
163 |
# File 'lib/rspec-steps/stepwise.rb', line 163 def then(*args, &block); example_synonym("then", *args, &block); end |
#when(*args, &block) ⇒ Object
162 |
# File 'lib/rspec-steps/stepwise.rb', line 162 def when(*args, &block); example_synonym("when", *args, &block); end |