Sha256: fee99ba19c4072a60686c76c901766500a96979d99d874886c5460adf71acd0c

Contents?: true

Size: 794 Bytes

Versions: 6

Compression:

Stored size: 794 Bytes

Contents

$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))

module MethodLog
  module SourceHelper
    def source(options = {})
      options[:source] = options[:source] ? unindent(options[:source]) : options[:source]
      SourceFile.new(options)
    end

    def unindent(code)
      lines = code.split($/)
      indent = lines.reject { |l| l.strip.length == 0 }.map { |l| l[/^\s*/].length }.min
      fixed_lines = lines.map { |l| l.sub(Regexp.new(' ' * indent), '') }
      fixed_lines.drop_while { |l| l.strip.length == 0 }.take_while { |l| l.strip.length > 0 }.join($/)
    end

    def indent(code, spaces = 2)
      lines = code.split($/)
      lines.map { |l| "#{' ' * spaces}#{l}"}.join($/)
    end
  end
end

RSpec.configure do |config|
  config.include MethodLog::SourceHelper
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
method_log-0.2.1 spec/spec_helper.rb
method_log-0.2.0 spec/spec_helper.rb
method_log-0.1.1 spec/spec_helper.rb
method_log-0.1.0 spec/spec_helper.rb
method_log-0.0.7 spec/spec_helper.rb
method_log-0.0.6 spec/spec_helper.rb