### Basic RSpec Test for Rails Generator Source: https://github.com/stevehodgkiss/generator_spec/blob/master/README.md Demonstrates a basic RSpec test file for a Rails generator. It sets the destination path, defines generator arguments, prepares the destination directory, runs the generator, and asserts the creation of a specific file with expected content. ```ruby # spec/lib/generators/test/test_generator_spec.rb require "generator_spec" describe TestGenerator, type: :generator do destination File.expand_path("../../tmp", __FILE__) arguments %w(something) before(:all) do prepare_destination run_generator end it "creates a test initializer" do assert_file "config/initializers/test.rb", "# Initializer" end end ``` -------------------------------- ### RSpec Test with Custom Structure Matcher Source: https://github.com/stevehodgkiss/generator_spec/blob/master/README.md Shows how to use generator_spec's custom RSpec matcher for asserting file structures. This approach allows for detailed checks, including file existence, content presence, and absence of specific text within files, organized hierarchically. ```ruby describe TestGenerator, "using custom matcher", type: :generator do destination File.expand_path("../../tmp", __FILE__) before do prepare_destination run_generator end specify do expect(destination_root).to have_structure { no_file "test.rb" directory "config" do directory "initializers" do file "test.rb" do contains "# Initializer" does_not_contain "Something else" end end end directory "db" do directory "migrate" do file "123_create_tests.rb" migration "create_tests" do contains "class TestMigration" does_not_contain "Something else" end end end } end end ``` -------------------------------- ### Add generator_spec Gem to Gemfile Source: https://github.com/stevehodgkiss/generator_spec/blob/master/README.md Include the generator_spec gem in your test group within the Gemfile to enable its functionality for testing Rails generators. This is a prerequisite for using the gem's features. ```ruby group :test do gem "generator_spec" end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.