Top Level Namespace

Defined Under Namespace

Modules: Cucumber

Instance Method Summary collapse

Instance Method Details

#create_missing_model(singular_name) ⇒ Object



30
31
32
33
34
35
# File 'lib/neverfails.rb', line 30

def create_missing_model(singular_name)
  # Generate the model and the migration
  Rails::Generators.invoke("model", [singular_name, "--orm=active_record", "--migration"])
  # Run the migration
  ActiveRecord::Migrator.migrate "db/migrate/"
end

#create_missing_page_listing(objects) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/neverfails.rb', line 37

def create_missing_page_listing(objects)
  # Generate the controller
  Rails::Generators.invoke("controller", [objects.classify.pluralize, "index"])
  # Add an extra route match "/models" => "model#index"
  @@missing_view_file = "app/views/#{objects}/index.html.erb"
  routes_file = 'config/routes.rb'
  old_routes = File.read(routes_file)
  File.open(routes_file, "w") do |file| 
    file.puts old_routes.gsub(/get "#{objects}\/index"/, 
    "get \"#{objects}/index\"\nmatch \"/#{objects}\" => \"#{objects}#index\"")
  end      
  # Reload routes
  ::Rails.application.reload_routes!
end

#create_missing_text(text) ⇒ Object



52
53
54
55
56
57
# File 'lib/neverfails.rb', line 52

def create_missing_text(text)
  File.open(@@missing_view_file, "w") do |file| 
    file.puts "#{text}\n"
  end
  Capybara.current_session.visit $last_url
end