Class: RubocopRspecCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_learner/rubocop_rspec_check.rb

Instance Method Summary collapse

Constructor Details

#initialize(local_dir, gem_dir) ⇒ RubocopRspecCheck

Returns a new instance of RubocopRspecCheck.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ruby_learner/rubocop_rspec_check.rb', line 8

def initialize(local_dir, gem_dir)
  @local_dir = local_dir
  @workshop_dir = "#{local_dir}/workshop"
  @restore_dir = "#{local_dir}/restore"
  @data_dir = "#{local_dir}/.data"
  @gem_dir = gem_dir
  theme_color = ""
  File.open("#{@data_dir}/theme_color.txt") do |f|
    theme_color = f.gets.chomp
  end
  @emacs_dir = "#{@data_dir}/.emacs.d/#{theme_color}"
end

Instance Method Details

#action(mode_dir: String, is_copy: Bool) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ruby_learner/rubocop_rspec_check.rb', line 21

def action(mode_dir: String, is_copy: Bool)
  start_time = Time.now
  if is_copy
    %w{lib/workplace.rb lib/sentence.org lib/answer.rb spec/workplace_spec.rb}.each do |path|
      FileUtils.cp("#{mode_dir}/#{path}", "#{@workshop_dir}/#{path}")
    end
  end
  system "cd #{@workshop_dir}/lib && emacs -nw -q -l #{@emacs_dir}/init.el sentence.org workplace.rb"
  loop do
    flag_rspec, flag_rs_exit = rspec_check
    break if flag_rs_exit == true
    flag_rubocop, flag_rub_exit = rubocop_check
    break if flag_rub_exit == true
    if flag_rspec == true && flag_rubocop == true
      puts "**********************************"
      puts "Final Error Check"
      puts "**********************************"
      stdout, stderr, status = Open3.capture3("rspec #{@workshop_dir}/spec/workplace_spec.rb")
      if status == 0
        puts "your code is perfect."
        puts 'If you want to run your code, you execute the following command.'
        puts " $ ruby #{@workshop_dir}/lib/workplace.rb"
        break
      else
        puts "not perfect, please fix your code."
      end
    end
  end
  elapsed_time = Common.allocate.time_check(start_time: start_time)
  p "#{elapsed_time} sec"
  restore = Restore.new
  restore.save(file: "#{@workshop_dir}/lib/workplace.rb", elapsed_time: elapsed_time)
end