Class: Spork::TestFramework
- Inherits:
-
Object
- Object
- Spork::TestFramework
- Defined in:
- lib/spork/test_framework.rb
Defined Under Namespace
Classes: Cucumber, FactoryException, FrameworkNotAvailable, NoFrameworkMatched, NoFrameworksAvailable, RSpec
Constant Summary collapse
- LOAD_PREFERENCE =
['RSpec', 'Cucumber']
- BOOTSTRAP_FILE =
File.dirname(__FILE__) + "/../../assets/bootstrap.rb"
- @@supported_test_frameworks =
[]
Instance Attribute Summary collapse
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Class Method Summary collapse
-
.available? ⇒ Boolean
Returns true if the testing frameworks helper file exists.
-
.available_test_frameworks ⇒ Object
Returns a list of all testing servers that have detected their testing framework being used in the project.
- .default_port ⇒ Object
- .factory(output = STDOUT, error = STDERR, beginning_with = nil) ⇒ Object
- .helper_file ⇒ Object
-
.load_preference_index ⇒ Object
Used to specify.
- .short_name ⇒ Object
-
.supported_test_frameworks(starting_with = nil) ⇒ Object
Returns a list of all servers that have been implemented (it keeps track of them automatically via Class.inherited).
Instance Method Summary collapse
-
#bootstrap ⇒ Object
Bootstraps the current test helper file by prepending a Spork.prefork and Spork.each_run block at the beginning.
-
#bootstrapped? ⇒ Boolean
Detects if the test helper has been bootstrapped.
- #default_port ⇒ Object
- #entry_point ⇒ Object
- #helper_file ⇒ Object
-
#initialize(stdout = STDOUT, stderr = STDERR) ⇒ TestFramework
constructor
A new instance of TestFramework.
- #preload ⇒ Object
- #run_tests(argv, stderr, stdout) ⇒ Object
- #short_name ⇒ Object
Constructor Details
#initialize(stdout = STDOUT, stderr = STDERR) ⇒ TestFramework
Returns a new instance of TestFramework.
36 37 38 |
# File 'lib/spork/test_framework.rb', line 36 def initialize(stdout = STDOUT, stderr = STDERR) @stdout, @stderr = stdout, stderr end |
Instance Attribute Details
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
6 7 8 |
# File 'lib/spork/test_framework.rb', line 6 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
6 7 8 |
# File 'lib/spork/test_framework.rb', line 6 def stdout @stdout end |
Class Method Details
.available? ⇒ Boolean
Returns true if the testing frameworks helper file exists. Override if this is not sufficient to detect your testing framework.
110 111 112 |
# File 'lib/spork/test_framework.rb', line 110 def self.available? File.exist?(helper_file) end |
.available_test_frameworks ⇒ Object
Returns a list of all testing servers that have detected their testing framework being used in the project.
65 66 67 |
# File 'lib/spork/test_framework.rb', line 65 def self.available_test_frameworks supported_test_frameworks.select { |s| s.available? } end |
.default_port ⇒ Object
56 57 58 |
# File 'lib/spork/test_framework.rb', line 56 def self.default_port (ENV["#{short_name.upcase}_DRB"] || self::DEFAULT_PORT).to_i end |
.factory(output = STDOUT, error = STDERR, beginning_with = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/spork/test_framework.rb', line 40 def self.factory(output = STDOUT, error = STDERR, beginning_with = nil) if beginning_with @klass = supported_test_frameworks(beginning_with).first raise(NoFrameworkMatched.new(beginning_with)) if @klass.nil? raise(FrameworkNotAvailable.new(@klass)) unless @klass.available? else @klass = available_test_frameworks.first raise(NoFrameworksAvailable.new) unless @klass end @klass.new(output, error) end |
.helper_file ⇒ Object
52 53 54 |
# File 'lib/spork/test_framework.rb', line 52 def self.helper_file self::HELPER_FILE end |
.load_preference_index ⇒ Object
Used to specify
115 116 117 |
# File 'lib/spork/test_framework.rb', line 115 def self.load_preference_index LOAD_PREFERENCE.index(short_name) || LOAD_PREFERENCE.length end |
.short_name ⇒ Object
60 61 62 |
# File 'lib/spork/test_framework.rb', line 60 def self.short_name self.name.gsub('Spork::TestFramework::', '') end |
.supported_test_frameworks(starting_with = nil) ⇒ Object
Returns a list of all servers that have been implemented (it keeps track of them automatically via Class.inherited)
70 71 72 73 74 75 76 |
# File 'lib/spork/test_framework.rb', line 70 def self.supported_test_frameworks(starting_with = nil) @@supported_test_frameworks.sort! { |a,b| a.load_preference_index <=> b.load_preference_index } return @@supported_test_frameworks if starting_with.nil? @@supported_test_frameworks.select do |s| s.short_name.match(/^#{Regexp.escape(starting_with)}/i) end end |
Instance Method Details
#bootstrap ⇒ Object
Bootstraps the current test helper file by prepending a Spork.prefork and Spork.each_run block at the beginning.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/spork/test_framework.rb', line 92 def bootstrap if bootstrapped? stderr.puts "Already bootstrapped!" return end stderr.puts "Bootstrapping #{helper_file}." contents = File.read(helper_file) bootstrap_code = File.read(BOOTSTRAP_FILE) File.open(helper_file, "wb") do |f| f.puts bootstrap_code f.puts contents end stderr.puts "Done. Edit #{helper_file} now with your favorite text editor and follow the instructions." true end |
#bootstrapped? ⇒ Boolean
Detects if the test helper has been bootstrapped.
87 88 89 |
# File 'lib/spork/test_framework.rb', line 87 def bootstrapped? File.read(helper_file).include?("Spork.prefork") end |
#default_port ⇒ Object
153 154 155 |
# File 'lib/spork/test_framework.rb', line 153 def default_port self.class.default_port end |
#entry_point ⇒ Object
149 150 151 |
# File 'lib/spork/test_framework.rb', line 149 def entry_point bootstrapped? ? helper_file : framework.entry_point end |
#helper_file ⇒ Object
82 83 84 |
# File 'lib/spork/test_framework.rb', line 82 def helper_file self.class.helper_file end |
#preload ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/spork/test_framework.rb', line 119 def preload Spork.exec_prefork do if not bootstrapped? stderr.puts "#{helper_file} has not been bootstrapped. Run spork --bootstrap to do so." stderr.flush if framework.bootstrap_required? stderr.puts "I can't do anything for you by default for the framework you're using: #{framework.short_name}.\nYou must bootstrap #{helper_file} to continue." stderr.flush return false else load(framework.entry_point) end end framework.preload do if bootstrapped? stderr.puts "Loading Spork.prefork block..." stderr.flush load(helper_file) end end end true end |
#run_tests(argv, stderr, stdout) ⇒ Object
145 146 147 |
# File 'lib/spork/test_framework.rb', line 145 def run_tests(argv, stderr, stdout) raise NotImplementedError end |
#short_name ⇒ Object
78 79 80 |
# File 'lib/spork/test_framework.rb', line 78 def short_name self.class.short_name end |