class ActionsTest
Public Instance Methods
setup()
click to toggle source
Calls superclass method
# File railties/test/generators/actions_test.rb, line 14 def setup Quails.application = TestApp::Application super end
teardown()
click to toggle source
# File railties/test/generators/actions_test.rb, line 19 def teardown Quails.application = TestApp::Application.instance end
test_add_source_adds_source_to_gemfile()
click to toggle source
# File railties/test/generators/actions_test.rb, line 43 def test_add_source_adds_source_to_gemfile run_generator action :add_source, "http://gems.github.com" assert_file "Gemfile", /source 'http:\/\/gems\.github\.com'/ end
test_add_source_with_block_adds_source_to_gemfile_after_gem()
click to toggle source
# File railties/test/generators/actions_test.rb, line 57 def test_add_source_with_block_adds_source_to_gemfile_after_gem run_generator action :gem, "will-paginate" action :add_source, "http://gems.github.com" do gem "rspec-quails" end assert_file "Gemfile", /gem 'will-paginate'\nsource 'http:\/\/gems\.github\.com' do\n gem 'rspec-quails'\nend/ end
test_add_source_with_block_adds_source_to_gemfile_with_gem()
click to toggle source
# File railties/test/generators/actions_test.rb, line 49 def test_add_source_with_block_adds_source_to_gemfile_with_gem run_generator action :add_source, "http://gems.github.com" do gem "rspec-quails" end assert_file "Gemfile", /source 'http:\/\/gems\.github\.com' do\n gem 'rspec-quails'\nend/ end
test_capify_should_run_the_capify_command()
click to toggle source
# File railties/test/generators/actions_test.rb, line 342 def test_capify_should_run_the_capify_command content = capture(:stderr) do assert_called_with(generator, :run, ["capify .", verbose: false]) do action :capify! end end assert_match(/DEPRECATION WARNING: `capify!` is deprecated/, content) end
test_create_file_should_write_block_contents_to_file_path()
click to toggle source
# File railties/test/generators/actions_test.rb, line 38 def test_create_file_should_write_block_contents_to_file_path action(:create_file, "lib/test_file.rb") { "heres block data" } assert_file "lib/test_file.rb", "heres block data" end
test_create_file_should_write_data_to_file_path()
click to toggle source
# File railties/test/generators/actions_test.rb, line 33 def test_create_file_should_write_data_to_file_path action :create_file, "lib/test_file.rb", "heres test data" assert_file "lib/test_file.rb", "heres test data" end
test_env_option_should_win_over_quails_env_variable_when_running_quails()
click to toggle source
# File railties/test/generators/actions_test.rb, line 326 def test_env_option_should_win_over_quails_env_variable_when_running_quails assert_called_with(generator, :run, ["quails log:clear RAILS_ENV=production", verbose: false]) do with_quails_env "staging" do action :quails_command, "log:clear", env: "production" end end end
test_environment_should_include_block_contents_with_multiline_data_in_environment_initializer_block_with_env_option()
click to toggle source
# File railties/test/generators/actions_test.rb, line 178 def test_environment_should_include_block_contents_with_multiline_data_in_environment_initializer_block_with_env_option run_generator data = <<-RUBY config.encoding = "utf-8" config.time_zone = "UTC" RUBY action(:environment, nil, env: "development") { data } assert_file "config/environments/development.rb", /Quails\.application\.configure do\n#{Regexp.escape(data.strip_heredoc.indent(2))}/ end
test_environment_should_include_data_in_environment_initializer_block()
click to toggle source
# File railties/test/generators/actions_test.rb, line 140 def test_environment_should_include_data_in_environment_initializer_block run_generator autoload_paths = 'config.autoload_paths += %w["#{Quails.root}/app/extras"]' action :environment, autoload_paths assert_file "config/application.rb", / class Application < Quails::Application\n #{Regexp.escape(autoload_paths)}\n/ end
test_environment_should_include_data_in_environment_initializer_block_with_env_option()
click to toggle source
# File railties/test/generators/actions_test.rb, line 147 def test_environment_should_include_data_in_environment_initializer_block_with_env_option run_generator autoload_paths = 'config.autoload_paths += %w["#{Quails.root}/app/extras"]' action :environment, autoload_paths, env: "development" assert_file "config/environments/development.rb", /Quails\.application\.configure do\n #{Regexp.escape(autoload_paths)}\n/ end
test_environment_with_block_should_include_block_contents_in_environment_initializer_block()
click to toggle source
# File railties/test/generators/actions_test.rb, line 154 def test_environment_with_block_should_include_block_contents_in_environment_initializer_block run_generator action :environment do _ = "# This wont be added"# assignment to silence parse-time warning "unused literal ignored" "# This will be added" end assert_file "config/application.rb" do |content| assert_match(/# This will be added/, content) assert_no_match(/# This wont be added/, content) end end
test_environment_with_block_should_include_block_contents_with_multiline_data_in_environment_initializer_block()
click to toggle source
# File railties/test/generators/actions_test.rb, line 168 def test_environment_with_block_should_include_block_contents_with_multiline_data_in_environment_initializer_block run_generator data = <<-RUBY config.encoding = "utf-8" config.time_zone = "UTC" RUBY action(:environment) { data } assert_file "config/application.rb", / class Application < Quails::Application\n#{Regexp.escape(data.strip_heredoc.indent(4))}/ end
test_gem_falls_back_to_inspect_if_string_contains_single_quote()
click to toggle source
# File railties/test/generators/actions_test.rb, line 110 def test_gem_falls_back_to_inspect_if_string_contains_single_quote run_generator action :gem, "rspec", ">=2.0'0" assert_file "Gemfile", /^gem 'rspec', ">=2\.0'0"$/ end
test_gem_group_should_wrap_gems_in_a_group()
click to toggle source
# File railties/test/generators/actions_test.rb, line 126 def test_gem_group_should_wrap_gems_in_a_group run_generator action :gem_group, :development, :test do gem "rspec-quails" end action :gem_group, :test do gem "fakeweb" end assert_file "Gemfile", /\ngroup :development, :test do\n gem 'rspec-quails'\nend\n\ngroup :test do\n gem 'fakeweb'\nend/ end
test_gem_should_include_options()
click to toggle source
# File railties/test/generators/actions_test.rb, line 92 def test_gem_should_include_options run_generator action :gem, "rspec", github: "dchelimsky/rspec", tag: "1.2.9.rc1" assert_file "Gemfile", /gem 'rspec', github: 'dchelimsky\/rspec', tag: '1\.2\.9\.rc1'/ end
test_gem_should_insert_on_separate_lines()
click to toggle source
# File railties/test/generators/actions_test.rb, line 80 def test_gem_should_insert_on_separate_lines run_generator File.open("Gemfile", "a") { |f| f.write("# Some content...") } action :gem, "rspec" action :gem, "rspec-quails" assert_file "Gemfile", /^gem 'rspec'$/ assert_file "Gemfile", /^gem 'rspec-quails'$/ end
test_gem_should_put_gem_dependency_in_gemfile()
click to toggle source
# File railties/test/generators/actions_test.rb, line 66 def test_gem_should_put_gem_dependency_in_gemfile run_generator action :gem, "will-paginate" assert_file "Gemfile", /gem 'will\-paginate'/ end
test_gem_with_non_string_options()
click to toggle source
# File railties/test/generators/actions_test.rb, line 100 def test_gem_with_non_string_options run_generator action :gem, "rspec", require: false action :gem, "rspec-quails", group: [:development, :test] assert_file "Gemfile", /^gem 'rspec', require: false$/ assert_file "Gemfile", /^gem 'rspec-quails', group: \[:development, :test\]$/ end
test_gem_with_version_should_include_version_in_gemfile()
click to toggle source
# File railties/test/generators/actions_test.rb, line 72 def test_gem_with_version_should_include_version_in_gemfile run_generator action :gem, "rspec", ">=2.0.0.a5" assert_file "Gemfile", /gem 'rspec', '>=2.0.0.a5'/ end
test_gem_works_even_if_frozen_string_is_passed_as_argument()
click to toggle source
# File railties/test/generators/actions_test.rb, line 118 def test_gem_works_even_if_frozen_string_is_passed_as_argument run_generator action :gem, "frozen_gem".freeze, "1.0.0".freeze assert_file "Gemfile", /^gem 'frozen_gem', '1.0.0'$/ end
test_generate_should_run_script_generate_with_argument_and_options()
click to toggle source
# File railties/test/generators/actions_test.rb, line 260 def test_generate_should_run_script_generate_with_argument_and_options assert_called_with(generator, :run_ruby_script, ["bin/quails generate model MyModel", verbose: false]) do action :generate, "model", "MyModel" end end
test_git_with_hash_should_run_each_command_using_git_scm()
click to toggle source
# File railties/test/generators/actions_test.rb, line 194 def test_git_with_hash_should_run_each_command_using_git_scm assert_called_with(generator, :run, [ ["git rm README"], ["git add ."] ]) do action :git, rm: "README", add: "." end end
test_git_with_symbol_should_run_command_using_git_scm()
click to toggle source
# File railties/test/generators/actions_test.rb, line 188 def test_git_with_symbol_should_run_command_using_git_scm assert_called_with(generator, :run, ["git init"]) do action :git, :init end end
test_initializer_should_write_date_to_file_in_config_initializers()
click to toggle source
# File railties/test/generators/actions_test.rb, line 245 def test_initializer_should_write_date_to_file_in_config_initializers action :initializer, "constants.rb", "MY_CONSTANT = 42" assert_file "config/initializers/constants.rb", "MY_CONSTANT = 42\n" end
test_initializer_should_write_date_to_file_with_block_in_config_initializers()
click to toggle source
# File railties/test/generators/actions_test.rb, line 250 def test_initializer_should_write_date_to_file_with_block_in_config_initializers code = <<-RUBY MyLib.configure do |config| config.value = 123 end RUBY action(:initializer, "constants.rb") { code } assert_file "config/initializers/constants.rb", code.strip_heredoc end
test_invoke_other_generator_with_full_namespace()
click to toggle source
# File railties/test/generators/actions_test.rb, line 28 def test_invoke_other_generator_with_full_namespace action :invoke, "quails:model", ["my_model"] assert_file "app/models/my_model.rb", /MyModel/ end
test_invoke_other_generator_with_shortcut()
click to toggle source
# File railties/test/generators/actions_test.rb, line 23 def test_invoke_other_generator_with_shortcut action :invoke, "model", ["my_model"] assert_file "app/models/my_model.rb", /MyModel/ end
test_lib_should_write_data_to_file_in_lib()
click to toggle source
# File railties/test/generators/actions_test.rb, line 215 def test_lib_should_write_data_to_file_in_lib action :lib, "my_library.rb", "class MyLibrary" assert_file "lib/my_library.rb", "class MyLibrary\n" end
test_lib_should_write_data_to_file_with_block_in_lib()
click to toggle source
# File railties/test/generators/actions_test.rb, line 220 def test_lib_should_write_data_to_file_with_block_in_lib code = <<-RUBY class MyLib MY_CONSTANT = 123 end RUBY action(:lib, "my_library.rb") { code } assert_file "lib/my_library.rb", code.strip_heredoc end
test_log()
click to toggle source
# File railties/test/generators/actions_test.rb, line 419 def test_log assert_equal("YES\n", action(:log, "YES")) end
test_log_with_quiet()
click to toggle source
# File railties/test/generators/actions_test.rb, line 427 def test_log_with_quiet generator(default_arguments, quiet: true) assert_equal("", action(:log, "YES")) end
test_log_with_status()
click to toggle source
# File railties/test/generators/actions_test.rb, line 423 def test_log_with_status assert_equal(" yes YES\n", action(:log, :yes, "YES")) end
test_log_with_status_with_quiet()
click to toggle source
# File railties/test/generators/actions_test.rb, line 432 def test_log_with_status_with_quiet generator(default_arguments, quiet: true) assert_equal("", action(:log, :yes, "YES")) end
test_quails_should_run_rake_command_with_default_env()
click to toggle source
# File railties/test/generators/actions_test.rb, line 266 def test_quails_should_run_rake_command_with_default_env assert_called_with(generator, :run, ["rake log:clear RAILS_ENV=development", verbose: false]) do with_quails_env nil do action :rake, "log:clear" end end end
test_quails_with_env_option_should_run_rake_command_in_env()
click to toggle source
# File railties/test/generators/actions_test.rb, line 274 def test_quails_with_env_option_should_run_rake_command_in_env assert_called_with(generator, :run, ["rake log:clear RAILS_ENV=production", verbose: false]) do action :rake, "log:clear", env: "production" end end
test_rakefile_should_write_date_to_file_in_lib_tasks()
click to toggle source
# File railties/test/generators/actions_test.rb, line 230 def test_rakefile_should_write_date_to_file_in_lib_tasks action :rakefile, "myapp.rake", "task run: [:environment]" assert_file "lib/tasks/myapp.rake", "task run: [:environment]\n" end
test_rakefile_should_write_date_to_file_with_block_in_lib_tasks()
click to toggle source
# File railties/test/generators/actions_test.rb, line 235 def test_rakefile_should_write_date_to_file_with_block_in_lib_tasks code = <<-RUBY task rock: :environment do puts "Rockin'" end RUBY action(:rakefile, "myapp.rake") { code } assert_file "lib/tasks/myapp.rake", code.strip_heredoc end
test_readme()
click to toggle source
# File railties/test/generators/actions_test.rb, line 404 def test_readme run_generator assert_called(Quails::Generators::AppGenerator, :source_root, times: 2, returns: destination_root) do assert_match "application up and running", action(:readme, "README.md") end end
test_readme_with_quiet()
click to toggle source
# File railties/test/generators/actions_test.rb, line 411 def test_readme_with_quiet generator(default_arguments, quiet: true) run_generator assert_called(Quails::Generators::AppGenerator, :source_root, times: 2, returns: destination_root) do assert_no_match "application up and running", action(:readme, "README.md") end end
test_route_should_add_data_to_the_routes_block_in_config_routes()
click to toggle source
# File railties/test/generators/actions_test.rb, line 351 def test_route_should_add_data_to_the_routes_block_in_config_routes run_generator route_command = "route '/login', controller: 'sessions', action: 'new'" action :route, route_command assert_file "config/routes.rb", /#{Regexp.escape(route_command)}/ end
test_route_should_add_data_with_an_new_line()
click to toggle source
# File railties/test/generators/actions_test.rb, line 373 def test_route_should_add_data_with_an_new_line run_generator action :route, "root 'welcome#index'" route_path = File.expand_path("config/routes.rb", destination_root) content = File.read(route_path) # Remove all of the comments and blank lines from the routes file content.gsub!(/^ \#.*\n/, "") content.gsub!(/^\n/, "") File.open(route_path, "wb") { |file| file.write(content) } routes = <<-F Quails.application.routes.draw do root 'welcome#index' end F assert_file "config/routes.rb", routes action :route, "resources :product_lines" routes = <<-F Quails.application.routes.draw do resources :product_lines root 'welcome#index' end F assert_file "config/routes.rb", routes end
test_route_should_be_idempotent()
click to toggle source
# File railties/test/generators/actions_test.rb, line 358 def test_route_should_be_idempotent run_generator route_path = File.expand_path("config/routes.rb", destination_root) # runs first time, not asserting action :route, "root 'welcome#index'" content_1 = File.read(route_path) # runs second time action :route, "root 'welcome#index'" content_2 = File.read(route_path) assert_equal content_1, content_2 end
test_vendor_should_write_data_to_file_in_vendor()
click to toggle source
# File railties/test/generators/actions_test.rb, line 200 def test_vendor_should_write_data_to_file_in_vendor action :vendor, "vendor_file.rb", "# vendor data" assert_file "vendor/vendor_file.rb", "# vendor data\n" end
test_vendor_should_write_data_to_file_with_block_in_vendor()
click to toggle source
# File railties/test/generators/actions_test.rb, line 205 def test_vendor_should_write_data_to_file_with_block_in_vendor code = <<-RUBY puts "one" puts "two" puts "three" RUBY action(:vendor, "vendor_file.rb") { code } assert_file "vendor/vendor_file.rb", code.strip_heredoc end
Private Instance Methods
action(*args, &block)
click to toggle source
# File railties/test/generators/actions_test.rb, line 439 def action(*args, &block) capture(:stdout) { generator.send(*args, &block) } end