Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement middleware and version commands in the rage/cli.rb file. #99

Merged
merged 2 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/rage/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "thor"
require "rack"
require "rage/version"

module Rage
class CLI < Thor
Expand Down Expand Up @@ -112,6 +113,20 @@ def console
IRB.start
end

desc "middleware", "List Rack middleware stack enabled for the application"
def middleware
environment

Rage.config.middleware.middlewares.each do |middleware|
say "use #{middleware.first.name}"
end
end

desc "version", "Return the current version of the framework"
def version
puts Rage::VERSION
end

private

def environment
Expand Down
38 changes: 38 additions & 0 deletions spec/rage/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require "rage/cli"

RSpec.describe Rage::CLI do
subject(:rage_cli) { described_class.new }

describe "#middleware" do
before do
allow(rage_cli).to receive(:environment)
allow(Rage.config).to receive_message_chain(:middleware, :middlewares).and_return(middlewares)
end

context "when middleware stack is present" do
let(:middlewares) { [[Rage::FiberWrapper], [Rage::Reloader, [], nil]] }

it "lists the middleware stack" do
expect { rage_cli.middleware }.to output("use \Rage::FiberWrapper\nuse \Rage::Reloader\n").to_stdout
end
end

context "when middleware stack is empty" do
let(:middlewares) { [] }

it "does not list any middleware" do
expect { rage_cli.middleware }.to output("").to_stdout
end
end
end

describe "#version" do
before do
stub_const("Rage::VERSION", "1.0.0")
end

it "returns the current version of the framework" do
expect { rage_cli.version }.to output("1.0.0\n").to_stdout
end
end
end
Loading