Sha256: f1c9edfca69a603ae4c0eca907ad8a28cf5eab8c5162202bc7fb95fe0802ea90
Contents?: true
Size: 1.39 KB
Versions: 2
Compression:
Stored size: 1.39 KB
Contents
module RSpec module Debugging module LetVariables def let_variables let_variable_methods(self).keys end def let_variable_initialized?(name) __memoized.instance_variable_get("@memoized").key?(name) end def let_variable_get(name) __memoized.instance_variable_get("@memoized")[name] end def let_variable_locations(name) let_variable_methods(self)[name].map do |fn| normalize_path(fn.source_location.join(":")) end end def let_variable_values(name) let_variable_methods(self)[name].map do |fn| { normalize_path(fn.source_location.join(":")) => fn.bind(self).call } end end private extend self def let_variable_methods(example) # find RSpec modules containing `let` blocks mods = self.class.ancestors.select {|x| x.to_s.include?('::LetDefinitions') } locations = {} mods.each do |mod| mod.instance_methods.each do |method_name| locations[method_name] ||= [] locations[method_name] << mod.instance_method(method_name) end end locations end def normalize_path(path) path.delete_prefix( Dir.pwd + "/" ).gsub( %r{.*/gems/}, ".../gems/" ).sub(Dir.home, "~") end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rspec-debugging-0.0.2 | lib/rspec/debugging/let_variables.rb |
rspec-debugging-0.0.1 | lib/rspec/debugging/let_variables.rb |