Class: Brut::CLI::Apps::Scaffold::E2ETest

Inherits:
Commands::BaseCommand show all
Defined in:
lib/brut/cli/apps/scaffold.rb

Instance Attribute Summary

Attributes inherited from Commands::BaseCommand

#parent_command

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Commands::BaseCommand

#accepts, #argv, #bootstrap?, #commands, #default_command, #default_command_class, #default_rack_env, #env, #env_vars, #execute, #name, #options, #puts, #stderr, #stdin, #stdout, #system!

Class Method Details

.command_nameObject



109
# File 'lib/brut/cli/apps/scaffold.rb', line 109

def self.command_name = "test:e2e"

Instance Method Details

#args_descriptionObject



108
# File 'lib/brut/cli/apps/scaffold.rb', line 108

def args_description = "test_name"

#descriptionObject



107
# File 'lib/brut/cli/apps/scaffold.rb', line 107

def description = "Create the shell of an end-to-end test"

#optsObject



111
112
113
# File 'lib/brut/cli/apps/scaffold.rb', line 111

def opts = [
  ["--path PATH","Path within the e2e tests to create the file"],
]

#runObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/brut/cli/apps/scaffold.rb', line 115

def run
  if argv.empty?
    stderr.puts "'#{self.class.command_name}' requires a name"
    return 1
  end
  test_name = argv.join(" ").gsub(/\"/,"'")
  test_file_name = argv.join("_").gsub(/\W/,"_").gsub(/__+/,"_").downcase + ".spec.rb"
  test_file_dir = Brut.container.e2e_specs_dir
  if !options.path.nil?
    test_file_dir = test_file_dir / options.path
  end

  path_to_test_file = test_file_dir / test_file_name

  verb         = "Created"
  dry_run_verb = "create"

  if path_to_test_file.exist?
    if global_options.overwrite?
      verb         = "Overwrote"
      dry_run_verb = "overwrite"
    else
      stderr.puts "#{path_to_test_file.relative_path_from(Brut.container.project_root)} exists. Use --overwrite to replace it"
      return 1
    end
  end


    code = %{require "spec_helper"

RSpec.describe "#{test_name}" do
  it "should have tests" do
page.goto("/")
expect(page).to be_page_for(page_class_here)
  end
end}
  if global_options.dry_run?
    stdout.puts "Will #{dry_run_verb} #{path_to_test_file.relative_path_from(Brut.container.project_root)} with this code:"
    stdout.puts_no_prefix
    stdout.puts_no_prefix code
  else
    FileUtils.mkdir_p test_file_dir
    File.open(path_to_test_file,"w") do |file|
      file.puts code
    end
    stdout.puts "#{verb} #{path_to_test_file.relative_path_from(Brut.container.project_root)}"
  end
  0
end