Sha256: 005e7a587723515cb63f90102f48d0e5695a4934a837bc7a900b28e494a22eb1

Contents?: true

Size: 1.31 KB

Versions: 91

Compression:

Stored size: 1.31 KB

Contents

# encoding: utf-8
require 'spec_helper'
require 'eval_helper'

describe 'EvalHelper' do
  context :times_code do
    class EvalHelperTimesTest
      include EvalHelper

      def hoge(number, proc)
        code = times_code(number, proc)
      end
    end
    cases = [
      {
        case_no: 1,
        case_title: 'single_line_proc case',
        number: 2,
        proc: 'puts "#{i}times"',
        expected: '2.times { |i| puts "#{i}times" }'
      },
      {
        case_no: 2,
        case_title: 'multi_line_proc case',
        number: 3,
        proc: 'puts "#{i}times"\nputs "#{i*2}times"',
        expected: <<-EOS
3.times do |i|
  puts \"\#{i}times\"
  puts \"\#{i*2}times\"
end
        EOS
      },
    ]

    cases.each do |c|
      it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
        begin
          case_before c

          # -- given --
          # nothing

          # -- when --
          actual = EvalHelperTimesTest.new.hoge c[:number], c[:proc]

          # -- then --
          expect(actual).to eq(c[:expected])
        ensure
          case_after c
        end
      end

      def case_before(c)
        # implement each case before
      end

      def case_after(c)
        # implement each case after
      end
    end
  end
end

Version data entries

91 entries across 91 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.150 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.149 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.148 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.147 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.146 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.145 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.144 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.143 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.142 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.141 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.140 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.139 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.138 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.137 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.136 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.135 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.134 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.133 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.132 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.131 spec/eval_helper/times_code_spec.rb