Class: Calatrava::Kernel

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/calatrava/kernel.rb

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Kernel

Returns a new instance of Kernel.



8
9
10
# File 'lib/calatrava/kernel.rb', line 8

def initialize(root)
  @path = root
end

Instance Method Details

#coffee_filesObject



23
24
25
26
27
# File 'lib/calatrava/kernel.rb', line 23

def coffee_files
  Dir.chdir @path do
    Dir["kernel/app/*.coffee"] + Dir["kernel/plugins/*.coffee"]
  end
end

#coffee_pathObject



29
30
31
# File 'lib/calatrava/kernel.rb', line 29

def coffee_path
  (['app', 'app/plugins'] + features.collect { |m| "app/#{m[:name]}" }).join(':')
end

#featuresObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/calatrava/kernel.rb', line 12

def features
  Dir.chdir @path do
    Dir['kernel/app/*'].select { |n| File.directory? n }.collect do |n|
      {
        :name => File.basename(n),
        :coffee => Dir["#{n}/*.coffee"]
      }
    end
  end
end

#install_tasksObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/calatrava/kernel.rb', line 42

def install_tasks
  file '.node_updated' => 'package.json' do
    sh "npm install && touch .node_updated"
  end

  desc "Run jasmine test. If specs not given in argument, runs all test"
  task :spec => '.node_updated' do |t, args|
    cd "kernel" do
      ENV['NODE_PATH'] = "app:#{coffee_path}:spec:../assets/lib"
      sh "../node_modules/jasmine-node/bin/jasmine-node --coffee --test-dir spec"
    end
  end

  desc "Run cucumber.js features for kernel"
  task :features, [:file] => '.node_updated' do |t, args|
    prepare_for_features
    cd "kernel" do
      ENV['NODE_PATH'] = node_path_for_features
      features_to_be_run = args[:file] ? "#{kernel/features}/#{args[:file]}" : "features"
      sh "../node_modules/cucumber/bin/cucumber.js --tags @all,@kernel --tags ~@wip '#{features_to_be_run}'"
    end
  end

  namespace :features do
    task :wip => '.node_updated' do
      prepare_for_features
      cd "kernel" do
        ENV['NODE_PATH'] = node_path_for_features
        sh "../node_modules/cucumber/bin/cucumber.js --tags @wip --tags @kernel features"
      end
    end
  end

end

#node_path_for_featuresObject



38
39
40
# File 'lib/calatrava/kernel.rb', line 38

def node_path_for_features
  "#{coffee_path}:features/support:../assets/lib:features/step_definitions:../features/testdata"
end

#prepare_for_featuresObject



33
34
35
36
# File 'lib/calatrava/kernel.rb', line 33

def prepare_for_features
  sh "ln -sFfh kernel/features/step_definitions/ features/step_definitions"
  sh "ln -sFfh kernel/features/support/ features/support"
end