Permalink
Browse files

Add the ability to 'pretend' to execute commands

  • Loading branch information...
1 parent 33ba402 commit 700bc6356e489c562bfdbc0ad4fba50e69ac23e9 @rhburrows committed May 12, 2010
@@ -0,0 +1,15 @@
+Feature: Pretend Reviewr Execution
+
+ In order to better understand what reviewr is doing
+ As a reviewr user/developer
+ I want a pretend mode that outputs commands without executing them
+
+ Background:
+ Given I am in the working directory of a git repository
+ And assuming I enter valid email account information
+
+ Scenario: Pretend Request
+ When I run "reviewr -p request reviewer@site.com"
+ # There's probably a better way to check this but now I don't care about
+ # repo state
+ Then I should see "git remote show origin"
@@ -19,6 +19,10 @@
git_executed?("git branch #{name} master").should be_true
end
+Then /^reviewr should not create a new branch called "([^\"]*)"$/ do |name|
+ git_executed?("git branch #{name} master").should be_false
+end
+
Then /^reviewr should create a commit with message:$/ do |msg|
last_commit_msg.should == msg
end
@@ -32,7 +32,7 @@
end
Then /^I should see "([^\"]*)"$/ do |msg|
- output.messages.should include(msg)
+ output.messages.map(&:chomp).should include(msg.chomp)
end
Then /^the email should be set to "([^\"]*)"$/ do |email|
@@ -33,6 +33,10 @@ def messages
def print(message)
messages << message
end
+
+ def puts(message)
+ print("#{message}\n")
+ end
end
def output
View
@@ -2,6 +2,7 @@
require 'reviewr/cli'
require 'reviewr/git'
+require 'reviewr/pretend_git'
require 'reviewr/mailer'
require 'reviewr/project'
require 'reviewr/version'
View
@@ -8,6 +8,10 @@ class Main
def initialize(args, input = STDIN, output = STDOUT)
@command = args.shift
+ if @command == "-p"
+ Git.instance = PretendGit.new(output)
+ @command = args.shift
+ end
@arguments = args
@input, @output = input, output
end
View
@@ -0,0 +1,47 @@
+module Reviewr
+ class PretendGit < Git
+ attr_reader :output
+
+ def initialize(output)
+ @output = output
+ end
+
+ def rebase(base, branch)
+ pretend_execute("git rebase #{base} #{branch}")
+ true
+ end
+
+ def create_branch(branch_name, base)
+ pretend_execute("git branch #{branch_name} #{base}")
+ end
+
+ def commit(msg)
+ pretend_execute("git commit --allow-empty -m \"#{msg}\"")
+ end
+
+ def change_branch(branch_name)
+ pretend_execute("git checkout #{branch_name}")
+ end
+
+ def fetch(branch_name)
+ pretend_execute("git fetch #{remote_repo} #{branch_name}")
+ end
+
+ def push_branch(branch_name)
+ pretend_execute("git push #{remote_repo} #{branch_name}")
+ end
+
+ def cherry_pick(commit)
+ pretend_execute("git cherry-pick -s #{commit}")
+ end
+
+ def execute(cmd)
+ output.puts(cmd)
+ super(cmd)
+ end
+
+ def pretend_execute(cmd)
+ output.puts(cmd)
+ end
+ end
+end
@@ -3,14 +3,42 @@
module Reviewr::CLI
describe Main do
describe "#initialize" do
- it "takes the first argument as the command name" do
- main = Main.new(["a", "b"])
- main.command.should == "a"
+ context "-p is not specified" do
+ it "takes the first argument as the command name" do
+ main = Main.new(["a", "b"])
+ main.command.should == "a"
+ end
+
+ it "takes the rest of the arguments as the arguments" do
+ main = Main.new(["a", "b", "c"])
+ main.arguments.should == ["b", "c"]
+ end
end
- it "takes the rest of the arguments as the arguments" do
- main = Main.new(["a", "b", "c"])
- main.arguments.should == ["b", "c"]
+ context "-p is specified" do
+ it "Creates a pretend Git" do
+ input = mock("input")
+ output = mock("output")
+ Reviewr::PretendGit.should_receive(:new).with(output)
+ Main.new(["-p", "a", "b"], input, output)
+ end
+
+ it "Sets the pretend Git as the instance" do
+ pretend_git = mock("Pretend Git")
+ Reviewr::PretendGit.stub(:new).and_return(pretend_git)
+ Main.new(["-p"])
+ Reviewr::Git.instance.should == pretend_git
+ end
+
+ it "takes the second argument as the command name" do
+ main = Main.new(["-p", "a", "b"])
+ main.command.should == "a"
+ end
+
+ it "takes the rest of the arguments as the arguments" do
+ main = Main.new(["-p", "a", "b"])
+ main.arguments.should == ["b"]
+ end
end
end
@@ -0,0 +1,63 @@
+require 'spec_helper'
+
+module Reviewr
+ describe PretendGit do
+ let(:output){ mock("Output").as_null_object }
+ let(:p_git){ PretendGit.new(output) }
+
+ describe "#rebase" do
+ it "pretends to rebase" do
+ output.should_receive(:puts).with('git rebase base branch')
+ p_git.rebase('base', 'branch')
+ end
+
+ it "returns true" do
+ p_git.rebase('base', 'branch').should be_true
+ end
+ end
+
+ describe "#create_branch" do
+ it "pretends to create a branch" do
+ output.should_receive(:puts).with("git branch name base")
+ p_git.create_branch('name', 'base')
+ end
+ end
+
+ describe "#commit" do
+ it "pretends to commit" do
+ output.should_receive(:puts).with("git commit --allow-empty -m \"msg\"")
+ p_git.commit("msg")
+ end
+ end
+
+ describe "#change_branch" do
+ it "pretends to change branches" do
+ output.should_receive(:puts).with("git checkout branch")
+ p_git.change_branch('branch')
+ end
+ end
+
+ describe "#fetch" do
+ it "pretends to fetch" do
+ output.should_receive(:puts).with("git fetch repo branch")
+ p_git.remote_repo = 'repo'
+ p_git.fetch('branch')
+ end
+ end
+
+ describe "#push_branch" do
+ it "pretends to push the branch" do
+ output.should_receive(:puts).with("git push repo branch")
+ p_git.remote_repo = 'repo'
+ p_git.push_branch('branch')
+ end
+ end
+
+ describe "#cherry_pick" do
+ it "pretends to cherry pick" do
+ output.should_receive(:puts).with("git cherry-pick -s 12345678")
+ p_git.cherry_pick('12345678')
+ end
+ end
+ end
+end

0 comments on commit 700bc63

Please sign in to comment.