Module: Konacha

Defined in:
lib/konacha/reporter.rb,
lib/konacha.rb,
lib/konacha/engine.rb,
lib/konacha/runner.rb,
lib/konacha/server.rb,
lib/konacha/formatter.rb,
app/models/konacha/spec.rb,
lib/konacha/reporter/example.rb,
lib/konacha/reporter/metadata.rb,
lib/konacha/reporter/example_group.rb,
app/controllers/konacha/specs_controller.rb

Overview

The ExampleGroup class mimics the public interface of RSpec::Core::ExampleGroup.

Defined Under Namespace

Classes: Engine, Formatter, Reporter, Runner, Server, Spec, SpecsController

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.modeObject

Returns the value of attribute mode.



10
11
12
# File 'lib/konacha.rb', line 10

def mode
  @mode
end

Class Method Details

.asset_precompiled?(logical_path) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/konacha.rb', line 75

def asset_precompiled?(logical_path)
  precompiled_assets.include? logical_path
end

.configObject



24
25
26
# File 'lib/konacha.rb', line 24

def config
  Konacha::Engine.config.konacha
end

.configure {|config| ... } ⇒ Object

Yields:



28
29
30
# File 'lib/konacha.rb', line 28

def configure
  yield config
end

.precompiled_assetsObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/konacha.rb', line 64

def precompiled_assets
  %W(konacha.css
     chai.js
     mocha.js
     konacha/parent.js
     konacha/iframe.js
     konacha/runner.js).concat(spec_paths).map do |path|
    path.gsub(/\.js\.coffee$/, ".js").gsub(/\.coffee$/, ".js")
  end
end

.runObject



19
20
21
22
# File 'lib/konacha.rb', line 19

def run
  self.mode = :runner
  Konacha::Runner.start
end

.serveObject



12
13
14
15
16
17
# File 'lib/konacha.rb', line 12

def serve
  puts "Your tests are here:"
  puts "  http://#{host}:#{port}/"
  self.mode = :server
  Konacha::Server.start
end

.spec_pathsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/konacha.rb', line 38

def spec_paths
  spec_root.flat_map do |root|
    # Support Sprockets 2.x
    if Rails.application.assets.respond_to?(:each_entry)
      paths = Rails.application.assets.each_entry(root).find_all { |pathname|
        config.spec_matcher === pathname.basename.to_s &&
        (pathname.extname == '.js' || Tilt[pathname]) &&
        Rails.application.assets.content_type_of(pathname) == 'application/javascript'
      }
    # Sprockets 3
    elsif Rails.application.assets.respond_to?(:each_file)
      paths = Rails.application.assets.each_file.find_all { |path|
        pathname = Pathname.new(path)
        pathname.dirname.to_s.start_with?(root) &&
          config.spec_matcher === pathname.basename.to_s &&
          (pathname.extname == '.js' || Tilt[pathname])
      }
    else
      raise NotImplementedError.new("Konacha is not compatible with the version of Sprockets used by your application.")
    end
    paths.map { |pathname|
      pathname.to_s.gsub(File.join(root, ''), '')
    }.sort
  end
end

.spec_rootObject



34
35
36
# File 'lib/konacha.rb', line 34

def spec_root
  [config.spec_dir].flatten.map {|d| File.join(Rails.root, d)}
end

.sprockets_rails_3?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/konacha.rb', line 79

def sprockets_rails_3?
  defined?(Sprockets::Rails::VERSION) && Sprockets::Rails::VERSION.start_with?('3')
end