Class: MSpec::Opal::Environment
- Defined in:
- opal/lib/mspec/opal/rake_task.rb
Instance Attribute Summary collapse
-
#basedir ⇒ Object
readonly
Returns the value of attribute basedir.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
- #add_files(specs, tag = '') ⇒ Object
- #build_min(file = "#{basedir}/build/specs.min.js") ⇒ Object
- #build_specs(file = "#{basedir}/build/specs.js") ⇒ Object
- #files ⇒ Object
- #files_to_run(pattern = nil) ⇒ Object
-
#initialize(basedir = nil, pattern = nil) ⇒ Environment
constructor
A new instance of Environment.
- #paths_from_glob(pattern) ⇒ Object
- #rubyspec_black_list ⇒ Object
- #rubyspec_paths_in_dir(dirname, path) ⇒ Object
- #rubyspec_white_list ⇒ Object
- #specs ⇒ Object
- #stubs ⇒ Object
Constructor Details
#initialize(basedir = nil, pattern = nil) ⇒ Environment
Returns a new instance of Environment
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'opal/lib/mspec/opal/rake_task.rb', line 106 def initialize(basedir = nil, pattern = nil) @pattern = pattern @basedir = basedir = File.(basedir || DEFAULT_BASEDIR) ::Opal.append_path basedir ::Opal.use_gem 'mspec' stubs.each do |asset| ::Opal::Processor.stub_file asset end ENV['OPAL_SPEC'] ||= files_to_run(pattern).join(',') super() ::Opal.paths.each { |p| append_path p } end |
Instance Attribute Details
#basedir ⇒ Object (readonly)
Returns the value of attribute basedir
104 105 106 |
# File 'opal/lib/mspec/opal/rake_task.rb', line 104 def basedir @basedir end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern
104 105 106 |
# File 'opal/lib/mspec/opal/rake_task.rb', line 104 def pattern @pattern end |
Instance Method Details
#add_files(specs, tag = '') ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'opal/lib/mspec/opal/rake_task.rb', line 150 def add_files specs, tag = '' tag = "[#{tag}] " puts "#{tag}Adding #{specs.size} spec files..." specs = specs.flatten.map do |path| dirname = File.join([basedir, path]) if File.directory? dirname rubyspec_paths_in_dir(dirname, path) else path end end.flatten files.concat specs end |
#build_min(file = "#{basedir}/build/specs.min.js") ⇒ Object
141 142 143 144 |
# File 'opal/lib/mspec/opal/rake_task.rb', line 141 def build_min file = "#{basedir}/build/specs.min.js" require 'opal/util' build ::Opal::Util.uglify(specs.to_s), file end |
#build_specs(file = "#{basedir}/build/specs.js") ⇒ Object
211 212 213 214 215 216 |
# File 'opal/lib/mspec/opal/rake_task.rb', line 211 def build_specs file = "#{basedir}/build/specs.js" code = specs.to_s FileUtils.mkdir_p File.dirname(file) puts "Building #{file}..." File.open(file, 'w+') { |o| o << code } end |
#files ⇒ Object
146 147 148 |
# File 'opal/lib/mspec/opal/rake_task.rb', line 146 def files @files ||= [] end |
#files_to_run(pattern = nil) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'opal/lib/mspec/opal/rake_task.rb', line 189 def files_to_run(pattern=nil) # add any filters in spec/filters of specs we dont want to run add_files paths_from_glob("#{basedir}/filters/**/*.rb"), :filters if pattern # add custom opal specs from spec/ add_files paths_from_glob(pattern) & rubyspec_white_list, :rubyspec_custom add_files paths_from_glob(pattern).grep(/(?!spec\/(corelib|stdlib)\/)/), :other_custom else # add opal specific specs add_files paths_from_glob("#{basedir}/opal/**/*_spec.rb"), :shared add_files paths_from_glob("#{basedir}/lib/lexer_spec.rb"), :lexer add_files paths_from_glob("#{basedir}/lib/parser/**/*_spec.rb"), :parser # add any rubyspecs we want to run (defined in spec/rubyspecs) add_files rubyspec_white_list, :rubyspecs end files - rubyspec_black_list end |
#paths_from_glob(pattern) ⇒ Object
164 165 166 167 168 |
# File 'opal/lib/mspec/opal/rake_task.rb', line 164 def paths_from_glob pattern Dir.glob(File.(pattern)).map do |s| s.sub(/\A#{basedir}\//, '').sub(/\.rb\z/, '') end end |
#rubyspec_black_list ⇒ Object
185 186 187 |
# File 'opal/lib/mspec/opal/rake_task.rb', line 185 def rubyspec_black_list @rubyspec_black_list ||= [] end |
#rubyspec_paths_in_dir(dirname, path) ⇒ Object
170 171 172 173 174 175 176 |
# File 'opal/lib/mspec/opal/rake_task.rb', line 170 def rubyspec_paths_in_dir(dirname, path) Dir.entries(dirname).select do |spec| spec.end_with? '.rb' end.map do |spec| File.join path, spec end end |
#rubyspec_white_list ⇒ Object
178 179 180 181 182 183 |
# File 'opal/lib/mspec/opal/rake_task.rb', line 178 def rubyspec_white_list File.read("#{basedir}/rubyspecs").split("\n").reject do |line| line.sub(/#.*/, '').strip.empty? || (line.start_with?('!') && rubyspec_black_list.push(line.sub('!', '') + '.rb')) end end |
#specs ⇒ Object
137 138 139 |
# File 'opal/lib/mspec/opal/rake_task.rb', line 137 def specs @specs ||= self['mspec/opal/main'] || raise("Cannot find mspec/opal/main inside #{paths.inspect}") end |
#stubs ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'opal/lib/mspec/opal/rake_task.rb', line 124 def stubs # missing stdlib stubs = %w[fileutils iconv yaml] # use x-strings which generate bad javascript stubs << "mspec/helpers/tmp" stubs << "mspec/helpers/environment" stubs << "mspec/guards/block_device" stubs << "mspec/guards/endian" stubs end |