Generate RSpec spec file for a Ruby class, module, or Rails component
Generates RSpec test files for Ruby classes, modules, or Rails components with appropriate spec structure.
/plugin marketplace add bastos/ruby-plugin-marketplace/plugin install rspec@ruby-plugin-marketplace<class_name or file_path>Create a new spec file for a given class, module, or Rails component.
The user provides either:
User, OrderProcessor, Api::V1::UsersControllerapp/models/user.rb, app/services/order_processor.rbFind the source file to understand the class structure:
# From class name: User -> app/models/user.rb
# From path: use directly
Read the source to identify:
Create spec file in corresponding location:
app/models/user.rb -> spec/models/user_spec.rb
app/services/foo/bar.rb -> spec/services/foo/bar_spec.rb
app/controllers/users_controller.rb -> spec/requests/users_spec.rb
lib/my_gem/parser.rb -> spec/lib/my_gem/parser_spec.rb
RSpec.describe User, type: :model do
describe "validations" do
# Based on model validations
end
describe "associations" do
# Based on model associations
end
describe "#method_name" do
it "description" do
pending "Add spec"
end
end
end
RSpec.describe OrderProcessor do
describe "#call" do
context "with valid input" do
it "processes successfully" do
pending "Add spec"
end
end
context "with invalid input" do
it "returns error" do
pending "Add spec"
end
end
end
end
RSpec.describe "Users", type: :request do
describe "GET /users" do
it "returns success" do
get users_path
expect(response).to have_http_status(:ok)
end
end
end
describe for the class/methodcontext for different scenarioslet blocks/rspec:generate User
/rspec:generate app/models/user.rb
/rspec:generate OrderProcessor
/rspec:generate Api::V1::UsersController
/generateGenerate ready-to-execute hypershift cluster creation commands from natural language descriptions
/generateGenerate documentation from TypeScript/JavaScript code, OpenAPI specs, GraphQL schemas, and SpecWeave specifications.