class Webspicy::Specification::Service
Attributes
resource[RW]
specification[RW]
Public Class Methods
info(raw)
click to toggle source
# File lib/webspicy/specification/service.rb, line 16 def self.info(raw) new(raw) end
new(raw)
click to toggle source
Calls superclass method
Webspicy::Support::DataObject::new
# File lib/webspicy/specification/service.rb, line 6 def initialize(raw) super(raw) bind_examples bind_counterexamples end
Public Instance Methods
config()
click to toggle source
# File lib/webspicy/specification/service.rb, line 20 def config specification.config end
counterexamples()
click to toggle source
# File lib/webspicy/specification/service.rb, line 60 def counterexamples @raw[:counterexamples] || [] end
default_example()
click to toggle source
# File lib/webspicy/specification/service.rb, line 52 def default_example @raw[:default_example] end
description()
click to toggle source
# File lib/webspicy/specification/service.rb, line 24 def description @raw[:description] end
dress_params(params)
click to toggle source
# File lib/webspicy/specification/service.rb, line 85 def dress_params(params) input_schema.dress(params) end
errconditions()
click to toggle source
# File lib/webspicy/specification/service.rb, line 44 def errconditions @errconditions ||= compile_errconditions end
error_schema()
click to toggle source
# File lib/webspicy/specification/service.rb, line 81 def error_schema @raw[:error_schema] end
examples()
click to toggle source
# File lib/webspicy/specification/service.rb, line 56 def examples @raw[:examples] || [] end
generated_counterexamples()
click to toggle source
# File lib/webspicy/specification/service.rb, line 64 def generated_counterexamples preconditions.map{|pre| pre.counterexamples(self).map{|tc| tc = config.factory.test_case(tc, Webspicy.current_scope) tc.bind(self, true) } }.flatten end
has_errconditions?()
click to toggle source
# File lib/webspicy/specification/service.rb, line 48 def has_errconditions? !errconditions.empty? end
has_postconditions?()
click to toggle source
# File lib/webspicy/specification/service.rb, line 40 def has_postconditions? !postconditions.empty? end
has_preconditions?()
click to toggle source
# File lib/webspicy/specification/service.rb, line 32 def has_preconditions? !preconditions.empty? end
input_schema()
click to toggle source
# File lib/webspicy/specification/service.rb, line 73 def input_schema @raw[:input_schema] end
output_schema()
click to toggle source
# File lib/webspicy/specification/service.rb, line 77 def output_schema @raw[:output_schema] end
postconditions()
click to toggle source
# File lib/webspicy/specification/service.rb, line 36 def postconditions @postconditions ||= compile_postconditions end
preconditions()
click to toggle source
# File lib/webspicy/specification/service.rb, line 28 def preconditions @preconditions ||= compile_preconditions end
to_s()
click to toggle source
# File lib/webspicy/specification/service.rb, line 89 def to_s "#{method} #{specification.url}" end
Private Instance Methods
bind_counterexamples()
click to toggle source
# File lib/webspicy/specification/service.rb, line 153 def bind_counterexamples counterexamples.each do |ex| ex.bind(self, true) end end
bind_examples()
click to toggle source
# File lib/webspicy/specification/service.rb, line 147 def bind_examples examples.each do |ex| ex.bind(self, false) end end
compile_conditions(descriptions, conditions)
click to toggle source
# File lib/webspicy/specification/service.rb, line 110 def compile_conditions(descriptions, conditions) # Because we want pre & post to be able to match in all cases # we need at least one condition descriptions = [Condition::MATCH_ALL] if descriptions.empty? mapping = {} instances = conditions.map{|c| instance = nil descr = descriptions.find do |d| instance = c.match(self, d) end instance.tap{|i| mapping[descr] ||= i if i i.matching_description = descr if i.respond_to?(:matching_description=) } }.compact mapped = descriptions .select{|d| mapping[d] } .map{|d| mapping[d] } unmapped = descriptions .reject{|d| mapping[d] } .select{|d| d.strip =~ /^(\(\w+\))?\(x\)/ } .map{|d| Postcondition::MissingConditionImpl.new.tap{|mc| mc.matching_description = d } } unexpected = descriptions .select{|d| mapping[d] } .select{|d| d.strip =~ /^(\(\w+\))?\( \)/ } .map{|d| Postcondition::UnexpectedConditionImpl.new.tap{|mc| mc.matching_description = d } } mapped + unmapped + unexpected end
compile_errconditions()
click to toggle source
# File lib/webspicy/specification/service.rb, line 105 def compile_errconditions @raw[:errconditions] = [@raw[:errconditions]] if @raw[:errconditions].is_a?(String) compile_conditions(@raw[:errconditions] ||= [], config.errconditions) end
compile_postconditions()
click to toggle source
# File lib/webspicy/specification/service.rb, line 100 def compile_postconditions @raw[:postconditions] = [@raw[:postconditions]] if @raw[:postconditions].is_a?(String) compile_conditions(@raw[:postconditions] ||= [], config.postconditions) end
compile_preconditions()
click to toggle source
# File lib/webspicy/specification/service.rb, line 95 def compile_preconditions @raw[:preconditions] = [@raw[:preconditions]] if @raw[:preconditions].is_a?(String) compile_conditions(@raw[:preconditions] ||= [], config.preconditions) end