Module: Webspicy

Defined in:
lib/webspicy.rb,
lib/webspicy/scope.rb,
lib/webspicy/client.rb,
lib/webspicy/tester.rb,
lib/webspicy/checker.rb,
lib/webspicy/version.rb,
lib/webspicy/resource.rb,
lib/webspicy/file_upload.rb,
lib/webspicy/precondition.rb,
lib/webspicy/configuration.rb,
lib/webspicy/postcondition.rb,
lib/webspicy/tester/asserter.rb,
lib/webspicy/resource/service.rb,
lib/webspicy/tester/assertions.rb,
lib/webspicy/client/http_client.rb,
lib/webspicy/client/rack_test_client.rb,
lib/webspicy/resource/service/test_case.rb,
lib/webspicy/resource/service/invocation.rb

Defined Under Namespace

Modules: Postcondition, Precondition, Version Classes: Checker, Client, Configuration, FileUpload, HttpClient, RackTestClient, Resource, Scope, Tester

Constant Summary collapse

ROOT_FOLDER =

About folders

Path.backfind('.[Gemfile]')
EXAMPLES_FOLDER =
ROOT_FOLDER/('examples')
FORMALDOC =

About formal doc and resources defined there

Finitio::DEFAULT_SYSTEM.parse (Path.dir/("webspicy/formaldoc.fio")).read
LOGGER =

Logging facade

::Logger.new(STDOUT)
VERSION =
"#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"

Class Method Summary collapse

Class Method Details

.current_scopeObject

Returns the current scope or a default one is none has been previously installed using ‘set_current_scope` or `with_scope`



96
97
98
# File 'lib/webspicy.rb', line 96

def current_scope
  Thread.current[:webspicy_scope] || default_scope
end

.debug(*args, &bl) ⇒ Object



140
141
142
# File 'lib/webspicy.rb', line 140

def debug(*args, &bl)
  LOGGER && LOGGER.debug(*args, &bl)
end

.default_scopeObject

Returns a default scope instance.



45
46
47
# File 'lib/webspicy.rb', line 45

def default_scope
  Scope.new(Configuration.new)
end

.info(*args, &bl) ⇒ Object



135
136
137
# File 'lib/webspicy.rb', line 135

def info(*args, &bl)
  LOGGER && LOGGER.info(*args, &bl)
end

.resource(raw, file = nil, scope = default_scope) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/webspicy.rb', line 50

def resource(raw, file = nil, scope = default_scope)
  with_scope(scope) do
    r = FORMALDOC["Resource"].dress(raw)
    r.located_at!(file) if file
    r
  end
end

.schema(fio) ⇒ Object

Parses a webservice schema (typically input or output) in the context of the current scope previously installed using ‘with_scope`.

If no scope has previously been installed, Finitio’s default system is used instead of another schema.



119
120
121
122
123
124
125
# File 'lib/webspicy.rb', line 119

def schema(fio)
  if scope = Thread.current[:webspicy_scope]
    scope.parse_schema(fio)
  else
    Finitio::DEFAULT_SYSTEM.parse(fio)
  end
end

.service(raw, scope = default_scope) ⇒ Object



59
60
61
62
63
# File 'lib/webspicy.rb', line 59

def service(raw, scope = default_scope)
  with_scope(scope) do
    FORMALDOC["Service"].dress(raw)
  end
end

.set_current_scope(scope) ⇒ Object

Sets the current scope.

This method is considered private and should not be used outside of Webspicy itself.



107
108
109
# File 'lib/webspicy.rb', line 107

def set_current_scope(scope)
  Thread.current[:webspicy_scope] = scope
end

.test_case(raw, scope = default_scope) ⇒ Object



66
67
68
69
70
# File 'lib/webspicy.rb', line 66

def test_case(raw, scope = default_scope)
  with_scope(scope) do
    FORMALDOC["TestCase"].dress(raw)
  end
end

.with_scope(scope) ⇒ Object

Yields the block after having installed ‘scope` globally.

This method makes sure that the scope will also be accessible for Finitio world schema parsing/dressing. Given that some global state is required (see “Schema” ADT, the dresser in particular, which calls ‘schema` later), the scope is put as a thread-local variable…

This method is considered private and should not be used outside of Webspicy itself.



84
85
86
87
88
89
# File 'lib/webspicy.rb', line 84

def with_scope(scope)
  scope = set_current_scope(scope)
  result = yield scope
  set_current_scope(nil)
  result
end