class Object
Public Instance Methods
detect_optimal_strategy_at(example)
click to toggle source
# File lib/factory_strategist/configure.rb, line 21 def detect_optimal_strategy_at(example) return unless run_successfully?(example) # when spec fails with create, no-op return put_best_strategy_at(example, :build) if run_successfully_with?("build", example) put_best_strategy_at(example, :build_stubbed) if run_successfully_with?("build_stubbed", example) end
example_replaced_from_create_to(method_name, example)
click to toggle source
# File lib/factory_strategist/configure.rb, line 45 def example_replaced_from_create_to(method_name, example) block_body = example.example.metadata[:block].body new_body = "Proc.new{ #{block_body.gsub("create", method_name.to_s)} }" eval(new_body) # rubocop:disable Security/Eval end
put_best_strategy_at(example, method)
click to toggle source
# File lib/factory_strategist/configure.rb, line 36 def put_best_strategy_at(example, method) p "#{example.location} create can be replaced to #{method}" end
run_successfully?(example)
click to toggle source
# File lib/factory_strategist/configure.rb, line 29 def run_successfully?(example) example.call true rescue StandardError false end
run_successfully_with?(method_name, example)
click to toggle source
# File lib/factory_strategist/configure.rb, line 40 def run_successfully_with?(method_name, example) ex = example_replaced_from_create_to(method_name, example) run_successfully?(ex) end