Skip to content

Commit

Permalink
Merge pull request #99 from rage-rb/cli-commands
Browse files Browse the repository at this point in the history
Implement `middleware` and `version` commands in the rage/cli.rb file.
  • Loading branch information
rsamoilov authored Sep 1, 2024
2 parents 15e80c8 + 24b2915 commit 36f8b16
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
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 @@ -115,6 +116,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

0 comments on commit 36f8b16

Please sign in to comment.