class Webspicy::Tester
Constants
- Checker
Attributes
client[R]
config[R]
hooks[R]
invocation[R]
invocation_error[R]
reporter[R]
result[R]
scope[R]
service[R]
spec_file[R]
specification[R]
test_case[R]
Public Class Methods
new(config)
click to toggle source
# File lib/webspicy/tester.rb, line 7 def initialize(config) @config = Configuration.dress(config) @scope = nil @hooks = nil @client = nil @spec_file = nil @specification = nil @service = nil @test_case = nil @invocation = nil @invocation_error = nil @reporter = @config.reporter end
Public Instance Methods
bind_condition(c)
click to toggle source
# File lib/webspicy/tester.rb, line 60 def bind_condition(c) c = Specification::Oldies::Bridge.new(c) unless c.respond_to?(:bind) c.bind(self) end
call()
click to toggle source
# File lib/webspicy/tester.rb, line 34 def call reporter.init(self) begin run_config rescue FailFast end reporter.report reporter.find(Reporter::SuccessOrNot).report end
call!()
click to toggle source
# File lib/webspicy/tester.rb, line 44 def call! res = call abort("KO") unless reporter.find(Reporter::SuccessOrNot).success? end
failfast?()
click to toggle source
# File lib/webspicy/tester.rb, line 30 def failfast? config.failfast end
find_and_call(method, url, mutation)
click to toggle source
# File lib/webspicy/tester.rb, line 49 def find_and_call(method, url, mutation) unless tc = scope.find_test_case(method, url) raise Error, "No such service `#{method} #{url}`" end mutated = tc.mutate(mutation) fork_tester(test_case: mutated) do |t| instrumented = t.instrument_test_case t.client.call(instrumented) end end
Protected Instance Methods
call_test_case_target()
click to toggle source
# File lib/webspicy/tester.rb, line 151 def call_test_case_target @invocation = nil @invocation_error = nil reporter.before_invocation @invocation = client.call(test_case) reporter.invocation_done rescue *PASSTHROUGH_EXCEPTIONS raise rescue => ex @invocation_error = ex reporter.invocation_done end
check_invocation()
click to toggle source
# File lib/webspicy/tester.rb, line 187 def check_invocation @result = Result.from(self) end
fork_tester(binding = {}) { |tap{|t| each_pair do |k,v| send(:"#{k}=", v)| ... }
click to toggle source
# File lib/webspicy/tester.rb, line 191 def fork_tester(binding = {}) yield dup.tap{|t| binding.each_pair do |k,v| t.send(:"#{k}=", v) end
instrument_one(condition)
click to toggle source
# File lib/webspicy/tester.rb, line 181 def instrument_one(condition) bind_condition(condition).instrument rescue ArgumentError raise "#{condition.class} implements old PRE/POST contract" end
instrument_test_case()
click to toggle source
# File lib/webspicy/tester.rb, line 164 def instrument_test_case service = test_case.service service.preconditions.each do |pre| instrument_one(pre) end service.postconditions.each do |post| instrument_one(post) end if test_case.example? service.errconditions.each do |err| instrument_one(err) end if test_case.counterexample? config.listeners(:instrument).each do |i| i.call(self) end test_case end
load_specification(spec_file)
click to toggle source
# File lib/webspicy/tester.rb, line 98 def load_specification(spec_file) @spec_file = spec_file reporter.before_spec_file config.factory.specification(spec_file.load, spec_file, scope) rescue *PASSTHROUGH_EXCEPTIONS raise rescue Exception => e reporter.spec_file_error(e) nil end
run_config()
click to toggle source
# File lib/webspicy/tester.rb, line 67 def run_config config.each_scope do |scope| @scope = scope @hooks = Support::Hooks.for(scope.config) @client = scope.get_client run_scope end end
run_scope()
click to toggle source
# File lib/webspicy/tester.rb, line 76 def run_scope reporter.before_all hooks.fire_before_all(self) reporter.before_all_done reporter.before_scope scope.each_specification_file do |spec_file| @specification = load_specification(spec_file) if @specification reporter.before_specification run_specification reporter.specification_done reporter.spec_file_done elsif failfast? raise FailFast end end reporter.scope_done reporter.after_all hooks.fire_after_all(self) reporter.after_all_done end
run_service()
click to toggle source
# File lib/webspicy/tester.rb, line 118 def run_service scope.each_testcase(service) do |test_case| @test_case = test_case reporter.before_test_case run_test_case reporter.test_case_done end end
run_specification()
click to toggle source
# File lib/webspicy/tester.rb, line 109 def run_specification scope.each_service(specification) do |service| @service = service reporter.before_service run_service reporter.service_done end end
run_test_case()
click to toggle source
# File lib/webspicy/tester.rb, line 127 def run_test_case hooks.fire_around(self) do reporter.before_each hooks.fire_before_each(self) reporter.before_each_done reporter.before_instrument instrument_test_case reporter.instrument_done call_test_case_target reporter.before_assertions check_invocation reporter.assertions_done reporter.after_each hooks.fire_after_each(self) reporter.after_each_done raise FailFast if !result.success? and failfast? end end