Module: Spectre

Defined in:
lib/spectre.rb,
lib/spectre/bag.rb,
lib/spectre/http.rb,
lib/spectre/async.rb,
lib/spectre/mixin.rb,
lib/spectre/logging.rb,
lib/spectre/reporter.rb,
lib/spectre/assertion.rb,
lib/spectre/resources.rb,
lib/spectre/diagnostic.rb,
lib/spectre/environment.rb,
lib/spectre/logging/file.rb,
lib/spectre/logging/console.rb

Defined Under Namespace

Modules: Assertion, Async, Bag, Curl, Delegator, Diagnostic, Environment, Http, Logging, Mixin, Reporter, Resources, Version Classes: DslClass, ExpectationFailure, RunInfo, Runner, Spec, SpecContext, SpectreError, SpectreSkip, Subject

Constant Summary collapse

VERSION =
[Version::MAJOR, Version::MINOR, Version::TINY].compact * '.'
@@subjects =
[]
@@modules =
[]

Class Method Summary collapse

Class Method Details

.configure(config) ⇒ Object



472
473
474
475
476
# File 'lib/spectre.rb', line 472

def configure config
  @@modules.each do |block|
    block.call(config)
  end
end

.delegate(*method_names, to: nil) ⇒ Object



464
465
466
# File 'lib/spectre.rb', line 464

def delegate *method_names, to: nil
  Spectre::Delegator.delegate(*method_names, to)
end

.describe(desc, &block) ⇒ Object



489
490
491
492
493
494
495
496
497
498
499
# File 'lib/spectre.rb', line 489

def describe desc, &block
  subject = @@subjects.find { |x| x.desc == desc }

  unless subject
    subject = Subject.new(desc)
    @@subjects << subject
  end

  ctx = SpecContext.new(subject)
  ctx._evaluate &block
end

.property(key, val) ⇒ Object



501
502
503
# File 'lib/spectre.rb', line 501

def property key, val
  Spectre::Runner.current.properties[key] = val
end

.purgeObject



478
479
480
481
# File 'lib/spectre.rb', line 478

def purge
  @@subjects = []
  @@modules = []
end

.register(&block) ⇒ Object



468
469
470
# File 'lib/spectre.rb', line 468

def register &block
  @@modules << block
end

.skip(message = nil) ⇒ Object

Raises:



505
506
507
# File 'lib/spectre.rb', line 505

def skip message=nil
  raise SpectreSkip.new(message)
end

.specs(spec_filter = [], tags = []) ⇒ Object



447
448
449
450
451
452
453
454
# File 'lib/spectre.rb', line 447

def specs spec_filter=[], tags=[]
  @@subjects
    .map { |x| x.specs }
    .flatten
    .select do |spec|
      (spec_filter.empty? or spec_filter.any? { |x| spec.name.match('^' + x.gsub('*', '.*') + '$') }) and (tags.empty? or tags.any? { |x| tag?(spec.tags, x) })
    end
end

.subjectsObject



443
444
445
# File 'lib/spectre.rb', line 443

def subjects
  @@subjects
end

.tag?(tags, tag_exp) ⇒ Boolean

Returns:

  • (Boolean)


456
457
458
459
460
461
462
# File 'lib/spectre.rb', line 456

def tag? tags, tag_exp
  tags = tags.map { |x| x.to_s }
  all_tags = tag_exp.split('+')
  included_tags = all_tags.select { |x| !x.start_with? '!' }
  excluded_tags = all_tags.select { |x| x.start_with? '!' }.map { |x| x[1..-1] }
  included_tags & tags == included_tags and excluded_tags & tags == []
end