This repository has been archived by the owner on Mar 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
247 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
*.gem | ||
|
||
.rspec | ||
.rvmrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
language: ruby | ||
rvm: | ||
- 1.9.3 | ||
- 2.0.0 | ||
branches: | ||
only: | ||
- examples | ||
- f/colour_switch | ||
gemfile: Gemfile | ||
notifications: | ||
recipients: | ||
- [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
source 'https://rubygems.org' | ||
|
||
gemspec | ||
|
||
group :development do | ||
gem 'rspec' | ||
gem 'rake' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rspec/core/rake_task' | ||
|
||
RSpec::Core::RakeTask.new(:all) | ||
|
||
task :default => :all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'bro' | ||
require 'bro' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,63 @@ | ||
class String | ||
def unindent | ||
gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "") | ||
end | ||
class FakeColor | ||
def initialize(text); @text = text; end | ||
|
||
def status | ||
self.colored.yellow | ||
%w{ red green yellow blue underline }.each do |m| | ||
define_method(m){ @text } | ||
end | ||
end | ||
|
||
def success | ||
self.colored.green.bold | ||
end | ||
class VanillaText | ||
class << self | ||
def apply | ||
String.class_eval do | ||
def colored | ||
FakeColor.new self | ||
end | ||
|
||
def unindent | ||
gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "") | ||
end | ||
end | ||
|
||
def problem | ||
self.colored.yellow_on_red_bold | ||
%w{ status success problem sorry important underline }.each do |m| | ||
String.class_eval do | ||
define_method(m){ self } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
def sorry | ||
self.colored.red.bold | ||
end | ||
class ColoredText | ||
class << self | ||
def apply | ||
String.class_eval do | ||
require 'smart_colored' | ||
|
||
def unindent | ||
gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "") | ||
end | ||
|
||
def status | ||
self.colored.yellow | ||
end | ||
|
||
def success | ||
self.colored.green.bold | ||
end | ||
|
||
def problem | ||
self.colored.yellow_on_red_bold | ||
end | ||
|
||
def sorry | ||
self.colored.red.bold | ||
end | ||
|
||
def important | ||
self.colored.magenta | ||
def important | ||
self.colored.magenta | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rspec' | ||
|
||
dirname = File.expand_path File.dirname(__FILE__) | ||
|
||
Dir.glob(File.join(dirname, "support", "**", "*.rb")).each{|f| require f} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class BroCli | ||
class << self | ||
def run(command) | ||
exe = File.join ".", "spec", "system.tests", "bin", "bro" | ||
|
||
`#{exe} #{command}` | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module BroSystemTest | ||
def bro(command) | ||
BroCli.run command | ||
end | ||
|
||
def bleach(text) | ||
ColourBlind.strip text | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class ColourBlind | ||
def self.strip(text) | ||
text.gsub(/\e\[(\d+)m/, '') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env ruby | ||
$LOAD_PATH.unshift File.expand_path(File.join("..", "bro", "lib")) | ||
require 'bro' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env ruby | ||
$LOAD_PATH.unshift File.expand_path(File.join("..", "bro", "lib")) | ||
puts $LOAD_PATH | ||
require 'bro' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "spec_helper" | ||
|
||
describe "The color switch" do | ||
include BroSystemTest | ||
|
||
let(:any_ansi_escape_sequence) { /\e\[(\d+)m/ } | ||
|
||
it "you can turn color off" do | ||
result = bro "--no-color" | ||
expect(result).to_not match any_ansi_escape_sequence | ||
end | ||
|
||
it "defaults to color on" do | ||
result = bro "" | ||
expect(result).to match any_ansi_escape_sequence | ||
end | ||
|
||
it "might be nice to cache the switch on disk in case you never want color" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'spec_helper' | ||
|
||
module BroSystemTest | ||
def bro(command) | ||
BroCli.run command | ||
end | ||
end | ||
|
||
describe "Basic examples" do | ||
include BroSystemTest | ||
|
||
it "can ask about curl for example" do | ||
result = bro "curl" | ||
|
||
expect(result).to match /[\d+] entries for curl/ | ||
end | ||
|
||
it "tells me when there is no manual for a command" do | ||
an_unknown_command = "xxx_unknown_command_xxx" | ||
|
||
result = bro an_unknown_command | ||
|
||
expect(result).to match /The #{an_unknown_command} command isn\'t in our database/ | ||
end | ||
|
||
it "you can turn color off" do | ||
result = bro "curl --no-color" | ||
expect(result).to match /[\d+] entries for curl/ | ||
end | ||
end | ||
|
||
class BroCli | ||
class << self | ||
def run(command) | ||
path = File.join ".", "spec", "system.tests", "bin", "bro" | ||
ColourBlind.strip `#{path} #{command}` | ||
end | ||
end | ||
end | ||
|
||
class ColourBlind | ||
def self.strip(text) | ||
text.gsub(/\e\[(\d+)m/, '') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'spec_helper' | ||
|
||
describe "Basic examples" do | ||
it "can be asked about a simple command" do | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'spec_helper' | ||
|
||
describe "Basic examples" do | ||
include BroSystemTest | ||
|
||
it "can ask about curl for example" do | ||
result = bro "curl" | ||
|
||
expect(result).to match /[\d+] entries for curl/ | ||
end | ||
|
||
it "tells me when there is no manual for a command" do | ||
an_unknown_command = "xxx_unknown_command_xxx" | ||
|
||
result = bleach (bro an_unknown_command) | ||
|
||
expect(result).to match /The #{an_unknown_command} command isn\'t in our database/ | ||
end | ||
end |