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

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

Instance Attribute Summary

Attributes inherited from Commands::BaseCommand

#parent_command

Instance Method Summary collapse

Methods inherited from BaseCommand

#bootstrap?, #default_rack_env

Methods inherited from Commands::BaseCommand

#accepts, #argv, #bootstrap?, #commands, #default_rack_env, #delegate_to_command, #detailed_description, #env, #env_vars, #execute, #options, #puts, #stdin, #system!, #theme

Instance Method Details

#args_descriptionObject



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

def args_description = "test_name"

#descriptionObject



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

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

#nameObject



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

def name = "e2e_test"

#optsObject



118
119
120
# File 'lib/brut/cli/apps/scaffold.rb', line 118

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

#runObject



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
164
165
166
167
168
169
170
# File 'lib/brut/cli/apps/scaffold.rb', line 122

def run
  if argv.empty?
    error "'#{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 options.overwrite?
      verb         = "Overwrote"
      dry_run_verb = "overwrite"
    else
      error "#{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 options.dry_run?
    puts "Will #{dry_run_verb} #{path_to_test_file.relative_path_from(Brut.container.project_root)} with this code:"
    puts
    puts code
  else
    FileUtils.mkdir_p test_file_dir
    File.open(path_to_test_file,"w") do |file|
      file.puts code
    end
    puts "#{verb} #{path_to_test_file.relative_path_from(Brut.container.project_root)}"
  end
  0
end