Method: Object#language_version

Defined in:
lib/extensions/mspec/mspec/helpers/language_version.rb

#language_version(dir, name) ⇒ Object

Helper for syntax-sensitive specs. The specs should be placed in a file in the versions subdirectory. For example, suppose language/method_spec.rb contains specs whose syntax depends on the Ruby version. In the language/method_spec.rb use the helper as follows:

language_version __FILE__, "method"

Then add a file “language/versions/method_1.8.rb” for the specs that are syntax-compatible with Ruby 1.8.x.

The most version-specific file will be loaded. If the version is 1.8.6, “method_1.8.6.rb” will be loaded if it exists, otherwise “method_1.8.rb” will be loaded if it exists.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/extensions/mspec/mspec/helpers/language_version.rb', line 17

def language_version(dir, name)
  path = File.dirname(File.expand_path(dir))

  [SpecGuard.ruby_version(:tiny), SpecGuard.ruby_version].each do |version|
    file = File.join path, "versions", "#{name}_#{version}.rb"
    if File.exists? file
      require file
      break
    end
  end

  nil
end