Class: Shoulda::Matchers::Integrations::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/matchers/integrations/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Configuration

Returns a new instance of Configuration.



12
13
14
15
16
17
18
19
20
# File 'lib/shoulda/matchers/integrations/configuration.rb', line 12

def initialize(&block)
  @test_frameworks = Set.new
  @libraries = Set.new

  test_framework :missing_test_framework
  library :missing_library

  block.call(self)
end

Instance Attribute Details

#test_frameworksObject (readonly)

Returns the value of attribute test_frameworks.



10
11
12
# File 'lib/shoulda/matchers/integrations/configuration.rb', line 10

def test_frameworks
  @test_frameworks
end

Class Method Details

.apply(&block) ⇒ Object



6
7
8
# File 'lib/shoulda/matchers/integrations/configuration.rb', line 6

def self.apply(&block)
  new(&block).apply
end

Instance Method Details

#applyObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/shoulda/matchers/integrations/configuration.rb', line 31

def apply
  if no_test_frameworks_added? && no_libraries_added?
    raise ConfigurationError, "shoulda-matchers is not configured correctly. You need to specify at least one\ntest framework and/or library. For example:\n\nShoulda::Matchers.configure do |config|\n  config.integrate do |with|\n    with.test_framework :rspec\n    with.library :rails\n  end\nend\n"
  end

  @test_frameworks.each do |test_framework|
    test_framework.include(Shoulda::Matchers::Independent)
    @libraries.each { |library| library.integrate_with(test_framework) }
  end

  self
end

#library(name) ⇒ Object



27
28
29
# File 'lib/shoulda/matchers/integrations/configuration.rb', line 27

def library(name)
  @libraries << Integrations.find_library!(name)
end

#test_framework(name) ⇒ Object



22
23
24
25
# File 'lib/shoulda/matchers/integrations/configuration.rb', line 22

def test_framework(name)
  clear_default_test_framework
  @test_frameworks << Integrations.find_test_framework!(name)
end