Skip to content
Browse files

wip after major rejigging and refactoring - def broken atm

  • Loading branch information...
1 parent 571f357 commit 48a9a7e9a03898d5dd6fcc66cd6e111835574dcb @markburns committed Mar 27, 2012
View
2 Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- kaboom (0.3.2)
+ kaboom (0.3.3)
active_support
json_pure (~> 1.5.3)
multi_json (~> 1.0.3)
View
204 lib/kaboom/command.rb
@@ -25,41 +25,98 @@ def storage
#
# args - The actual commands to operate on. Can be as few as zero
# arguments or as many as three.
+ # Returns output based on method calls.
def execute(*args)
- command = check_if_remote args
-
- major = args.shift
- minor = args.empty? ? nil : args.join(' ')
+ arguments = parse args
+ command = arguments.command
+
+ return help if(command and [45, "-"].include?(command[0]))
+
+ mapping = { "-v" => "version",
+ "--version" => "version",
+ "version" => "version",
+ "echo" => "echo",
+ "open" => "open" ,
+ "w" => "echo",
+ "o" => "open",
+ "rand" => "random",
+ "r" => "random",
+ "all" => "all",
+ "edit" => "edit",
+ "storage" => "storage",
+ "help" => "help",
+ "switch" => "switch"}
+
+ mapped = mapping[command]
+
+ return self.send(mapped, arguments) if mapped
return overview unless command
- delegate(command, major, minor)
+
+ major, minor = arguments.major, arguments.minor
+
+ if(minor == 'delete') and storage.item_exists?(major)
+ return delete_item(command, major)
+ end
+
+
+ if list = List.find(command)
+ return handle_list list, major, minor
+ end
+
+ if item = Item.find(command)
+ return say_clipboard item
+ end
+
+ create_list command, major, minor
end
+ Arguments = Struct.new :command, :major, :minor
- def check_if_remote args
+ def parse args
command = args.shift
if command == "remote"
Boom.use_remote
command = args.shift
end
- command
+
+ major = args.shift
+ minor = args.empty? ? nil : args.join(' ')
+
+ minor ||= stdin.read if pipable_input?
+
+ Arguments.new command, major, minor
end
- private :check_if_remote
+ private :parse
+
+ def say_clipboard
+ output "#{cyan("Boom!")} We just copied #{yellow(Platform.copy item)} to your clipboard."
+ end
+
+ def say_set list, key, value
+ output "#{c("Boom!")} #{y(key)} in #{y(list)} is #{y(value)}. Got it."
+ end
+
+ def handle_list list, major, minor
+ return list.delete if major == 'delete'
+ return list.detail unless major
+ return list.find_item major unless minor
+
+ list.add(Item.new(major,minor))
+ say_set list.name, major, minor
+ save
+ end
- # Public: gets $stdin.
- #
- # Returns the $stdin object. This method exists to help with easy mocking
- # or overriding.
def stdin
$stdin
end
- # Public: prints a tidy overview of your Lists in descending order of
- # number of Items.
- #
- # Returns nothing.
+ def pipable_input?
+ stdin.stat.size > 0
+ end
+
def overview
storage.lists.each do |list|
output " #{list.name} (#{list.items.size})"
@@ -88,76 +145,20 @@ def all
end
end
- # Public: allows main access to most commands.
- #
- # Returns output based on method calls.
- def delegate(command, major, minor)
- return all if command == 'all'
- return edit if command == 'edit'
- return switch(major) if command == 'switch'
- return show_storage if command == 'storage'
- return version if command == "-v"
- return version if command == "--version"
- return help if command == 'help'
- return help if command[0] == 45 || command[0] == '-' # any - dash options are pleas for help
- return echo(major,minor) if command == 'echo' || command == 'e'
- return open(major,minor) if command == 'open' || command == 'o'
- return random(major) if command == 'random' || command == 'rand' || command == 'r'
-
- # if we're operating on a List
- list = command
- if storage.list_exists?(list)
- return delete_list(list) if major == 'delete'
- return detail_list(list) unless major
- unless minor == 'delete'
- return add_item(list,major,minor) if minor
- return add_item(list,major,stdin.read) if stdin.stat.size > 0
- return search_list_for_item(list, major)
- end
- end
-
- if minor == 'delete' and storage.item_exists?(major)
- return delete_item(command, major)
- end
-
- return search_items(command) if storage.item_exists?(command)
-
- return create_list(command, major, stdin.read) if !minor && stdin.stat.size > 0
- return create_list(command, major, minor)
- end
-
- # Public: shows the current user's storage.
- #
- # Returns nothing.
def show_storage
- output "You're currently using #{Boom.config.attributes['backend']}."
+ output "You're currently using #{Boom.config['backend']}."
end
- # Public: switch to a new backend.
- #
- # backend - the String of the backend desired
- #
- # Returns nothing.
def switch(backend)
Storage.backend = backend
output "We've switched you over to #{backend}."
rescue NameError
output "We couldn't find that storage engine. Check the name and try again."
end
- # Public: prints all Items over a List.
- #
- # name - the List object to iterate over
- #
- # Returns nothing.
- def detail_list(name)
- list = List.find(name)
- list.items.sort{ |x,y| x.name <=> y.name }.each do |item|
- output " #{item.short_name}:#{item.spacer} #{item.value}"
- end
- end
+ def open arguments
+ key, value = arguments.major, arguments.minor
- def open(key, value)
if storage.list_exists?(key)
list = List.find(key)
if value
@@ -179,11 +180,8 @@ def not_found major, minor=nil
return output "#{yellow(minor)} #{red("not found in")} #{yellow(major)}"
end
-
- # Public: Opens a random item
- #
- # Returns nothing.
- def random(major)
+ def random arguments
+ major = arguments.major
if major.nil?
index = rand(storage.items.size)
item = storage.items[index]
@@ -194,18 +192,14 @@ def random(major)
else
output "We couldn't find that list."
end
- open(item.name, nil) unless item.nil?
+ open(Argument.new item.name) unless item.nil?
end
- # Public: echoes only the Item's value without copying
- #
- # item_name - the String term to search for in all Item names
- #
- # Returns nothing
- def echo(major, minor)
+ def echo arguments
+ major, minor = arguments.major, arguments.minor
if minor
- list = List.find(major)
- item = list.find_item(minor)
+ list = List.find major
+ item = list.find_item minor
else
item = storage.items.detect { |i| i.name == major }
end
@@ -266,10 +260,9 @@ def delete_list(name)
# Returns the newly created Item.
def add_item(list,name,value)
list = List.find(list)
- list.add_item(Item.new(name,value))
- output "#{cyan("Boom!")} #{yellow(name)} in #{yellow(list.name)} is #{yellow(value)}. Got it."
- save
- end
+ list.add(Item.new(name,value))
+ say_set list.name, name, value
+ end
# Public: remove a named Item.
#
@@ -295,19 +288,6 @@ def delete_item(list_name,name)
end
end
- # Public: search for an Item in all lists by name. Drops the
- # corresponding entry into your clipboard.
- #
- # name - the String term to search for in all Item names
- #
- # Returns the matching Item.
- def search_items(name)
- item = storage.items.detect do |item|
- item.name == name
- end
-
- output "#{cyan("Boom!")} We just copied #{yellow(Platform.copy(item))} to your clipboard."
- end
# Public: search for an Item in a particular list by name. Drops the
# corresponding entry into your clipboard if found.
@@ -327,12 +307,7 @@ def search_list_for_item(list_name, item_name)
end
end
- # Public: save in-memory data to disk.
- #
- # Returns whether or not data was saved.
- def save
- storage.save
- end
+ delegate :save, :to => :storage
# Public: the version of boom that you're currently running.
#
@@ -345,10 +320,11 @@ def version
#
# Returns nothing.
def edit
+ require 'ruby-debug'; debugger
if storage.respond_to?("json_file")
output "#{cyan("Boom!")} #{Platform.edit(storage.json_file)}"
else
- output "This storage backend does not store #{cyan("Boom!")} data on your computer"
+ output "This storage backend #{red storage.class} does not store #{cyan("Boom!")} data on your computer"
end
end
@@ -367,7 +343,7 @@ def r t
# Public: prints all the commands of boom.
#
# Returns nothing.
- def help
+ def help(arguments=nil)
#this currently looks horrible in code, but nice in output.
#would be good to make it both
View
22 lib/kaboom/config.rb
@@ -6,11 +6,11 @@
# as a Hash:
#
# config.attributes = { :backend => "JSON" }
-# config.attributes[:backend]
+# config[:backend]
# # => "json"
#
-# config.attributes[:backend] = "Redis"
-# config.attributes[:backend]
+# config[:backend] = "Redis"
+# config[:backend]
# # => "redis"
#
module Boom
@@ -38,6 +38,10 @@ def [] key
attributes[key]
end
+ def []= key, value
+ attributes[key] = value
+ end
+
# Public: creates a new instance of Config.
#
# This will load the attributes from boom's config file, or bootstrap it
@@ -100,17 +104,5 @@ def save
File.open(file, 'w') {|f| f.write(json) }
end
- def invalid_message
- %(#{red "Is your config correct? You said:"}
-
- #{File.read Boom.config.file}
-
- #{cyan "Our survey says:"}
-
- #{self.class.sample_config}
-
- #{yellow "Go edit "} #{Boom.config.file + yellow(" and make it all better") }
- ).gsub(/^ {8}/, '') # strip the first eight spaces of every line
- end
end
end
View
8 lib/kaboom/item.rb
@@ -28,6 +28,14 @@ def initialize(name,value)
@value = value
end
+ def self.find(name)
+ storage.items.detect { |i| i.name == name }
+ end
+
+ def self.storage
+ Boom.storage
+ end
+
# Public: the shortened String name of the Item. Truncates with ellipses if
# larger.
#
View
35 lib/kaboom/list.rb
@@ -12,9 +12,12 @@ class List
# name - The name of the List. Fails if already used.
#
# Returns the unpersisted List instance.
- def initialize(name)
- @items = []
+ def initialize(name, items=[])
@name = name
+
+ @items = items.map do |name, value|
+ Item.new(name,value)
+ end
end
# Public: accesses the in-memory JSON representation.
@@ -40,11 +43,24 @@ def self.storage
# item - the Item object to associate with this List.
#
# Returns the current set of items.
- def add_item(item)
+ def add(item)
delete_item(item.name) if find_item(item.name)
@items << item
end
+
+ # Public: prints all Items over a List.
+ #
+ # name - the List object to iterate over
+ #
+ # Returns nothing.
+ def detail
+ items.sort{ |x,y| x.name <=> y.name }.each do |item|
+ output " #{item.short_name}:#{item.spacer} #{item.value}"
+ end
+ end
+
+
# Public: finds any given List by name.
#
# name - String name of the list to search for
@@ -65,6 +81,14 @@ def self.delete(name)
previous != storage.lists.size
end
+ def delete
+ storage.lists = storage.lists.reject { |list| list.name == name }
+ end
+
+ def storage
+ self.class.storage
+ end
+
# Public: deletes an Item by name.
#
# name - String name of the item to delete
@@ -76,6 +100,8 @@ def delete_item(name)
previous != items.size
end
+ delegate :size, :to => :items
+
# Public: finds an Item by name. If the name is typically truncated, also
# allow a search based on that truncated name.
#
@@ -84,8 +110,7 @@ def delete_item(name)
# Returns the found item
def find_item(name)
items.find do |item|
- item.name == name ||
- item.short_name.gsub('','') == name.gsub('','')
+ item.name == name || item.short_name.gsub('','') == name.gsub('','')
end
end
View
4 lib/kaboom/storage.rb
@@ -10,12 +10,12 @@ module Storage
def self.backend=(backend)
backend = backend.capitalize
Boom::Storage.const_get(backend)
- Boom.config.attributes['backend'] = backend.downcase
+ Boom.config['backend'] = backend.downcase
Boom.config.save
end
def self.backend
- Boom::Storage.const_get(Boom.config.attributes['backend'].capitalize).new
+ Boom::Storage.const_get(Boom.config['backend'].capitalize).new
end
end
View
28 lib/kaboom/storage/base.rb
@@ -18,7 +18,7 @@ def initialize
populate
end
- # run bootstrap tasks for the storage
+ # run bootstrap tasks for the storage
def bootstrap ; end
# populate the in-memory store with all the lists and items
@@ -41,15 +41,10 @@ def save ; end
#
# Returns an Array of List objects.
def lists
- @lists.sort_by { |list| -list.items.size }
+ @lists.sort_by { |list| -list.size }
end
- # Public: tests whether a named List exists.
- #
- # name - the String name of a List
- #
- # Returns true if found, false if not.
- def list_exists?(name)
+ def find_list(name)
@lists.detect { |list| list.name == name }
end
@@ -81,11 +76,26 @@ def to_hash
def handle error, message
case error
when NoMethodError
- output cyan config_text
+ output invalid_config_message
when NameError
output message
end
+ exit -1
+ end
+
+ def invalid_config_message
+ %(#{red "Is your config correct? You said:"}
+
+ #{File.read Boom.config.file}
+
+ #{cyan "Our survey says:"}
+
+ #{self.class.sample_config}
+
+ #{yellow "Go edit "} #{Boom.config.file + yellow(" and make it all better") }
+ ).gsub(/^ {8}/, '') # strip the first eight spaces of every line
end
+
end
end
end
View
12 lib/kaboom/storage/gist.rb
@@ -37,7 +37,7 @@ def bootstrap
exit
end
- unless Boom.config.attributes["gist"]
+ unless Boom.config["gist"]
puts 'A "gist" data structure must be defined in ~/.boom.conf'
exit
end
@@ -64,7 +64,7 @@ def populate
items.each do |item|
item.each do |name,value|
- list.add_item(Item.new(name,value))
+ list.add(Item.new(name,value))
end
end
end
@@ -78,7 +78,7 @@ def save
private
def set_up_auth
- username, password = Boom.config.attributes["gist"]["username"], Boom.config.attributes["gist"]["password"]
+ username, password = Boom.config["gist"]["username"], Boom.config["gist"]["password"]
if username and password
self.class.basic_auth(username, password)
@@ -89,8 +89,8 @@ def set_up_auth
end
def find_or_create_gist
- @gist_id = Boom.config.attributes["gist"]["gist_id"]
- @public = Boom.config.attributes["gist"]["public"] == true
+ @gist_id = Boom.config["gist"]["gist_id"]
+ @public = Boom.config["gist"]["public"] == true
if @gist_id.nil? or @gist_id.empty?
response = self.class.post("/gists", request_params)
@@ -106,7 +106,7 @@ def find_or_create_gist
end
unless @gist_id
- Boom.config.attributes["gist"]["gist_id"] = @gist_id = response["id"]
+ Boom.config["gist"]["gist_id"] = @gist_id = response["id"]
Boom.config.save
end
end
View
11 lib/kaboom/storage/json.rb
@@ -15,7 +15,6 @@ class Json < Base
#
# Returns the String path of boom's Json representation.
def json_file
-
JSON_FILE
end
@@ -42,15 +41,7 @@ def populate
storage = MultiJson.decode(File.new(json_file, 'r').read)
storage['lists'].each do |lists|
- lists.each do |list_name, items|
- @lists << list = List.new(list_name)
-
- items.each do |item|
- item.each do |name,value|
- list.add_item(Item.new(name,value))
- end
- end
- end
+ @lists = lists.map { |name, items| List.new(name, items) }
end
end
View
2 lib/kaboom/storage/keychain.rb
@@ -43,7 +43,7 @@ def populate
stored_keychain_lists.each do |keychain|
@lists << list = List.new(keychain.scan(KEYCHAIN_FORMAT).flatten.first)
extract_keychain_items(keychain).each do |name|
- list.add_item(Item.new(name, extract_keychain_value(name, keychain)))
+ list.add(Item.new(name, extract_keychain_value(name, keychain)))
end
end
end
View
14 lib/kaboom/storage/mongodb.rb
@@ -28,13 +28,13 @@ def self.sample_config
# Returns Mongo connection
def mongo
@mongo ||= ::Mongo::Connection.new(
- Boom.config.attributes["mongodb"]["host"],
- Boom.config.attributes["mongodb"]["port"]
- ).db(Boom.config.attributes["mongodb"]["database"])
+ Boom.config["mongodb"]["host"],
+ Boom.config["mongodb"]["port"]
+ ).db(Boom.config["mongodb"]["database"])
@mongo.authenticate(
- Boom.config.attributes['mongodb']['username'],
- Boom.config.attributes['mongodb']['password']
+ Boom.config['mongodb']['username'],
+ Boom.config['mongodb']['password']
)
# Return connection
@@ -47,7 +47,7 @@ def mongo
#
# Returns the MongoDB collection
def collection
- @collection ||= mongo.collection(Boom.config.attributes["mongodb"]["collection"])
+ @collection ||= mongo.collection(Boom.config["mongodb"]["collection"])
end
# Public: Bootstrap
@@ -69,7 +69,7 @@ def populate
items.each do |item|
item.each do |name,value|
- list.add_item(Item.new(name,value))
+ list.add(Item.new(name,value))
end
end
end
View
6 lib/kaboom/storage/redis.rb
@@ -26,8 +26,8 @@ def self.sample_config
end
def redis
- @redis ||= ::Redis.new :host => Boom.config.attributes["redis"]["host"],
- :port => Boom.config.attributes["redis"]["port"]
+ @redis ||= ::Redis.new :host => Boom.config["redis"]["host"],
+ :port => Boom.config["redis"]["port"]
rescue Exception => exception
handle exception, "You don't have Redis installed yet:\n gem install redis"
end
@@ -47,7 +47,7 @@ def populate
shas.each do |item_sha|
name = redis.get "boom:items:#{item_sha}:name"
value = redis.get "boom:items:#{item_sha}:value"
- list.add_item(Item.new(name, value))
+ list.add(Item.new(name, value))
end
end
end
View
16 spec/color_spec.rb
@@ -2,28 +2,24 @@
describe Boom::Color do
it "colorize" do
- assert_equal "\e[35mBoom!\e[0m",
- Boom::Color.colorize("Boom!", :magenta)
+ Boom::Color.colorize("Boom!", :magenta).should =="\e[35mBoom!\e[0m"
end
it "magenta" do
- assert_equal "\e[35mMagenta!\e[0m",
- Boom::Color.magenta("Magenta!")
+ Boom::Color.magenta("Magenta!").should == "\e[35mMagenta!\e[0m"
end
it "red" do
- assert_equal "\e[31mRed!\e[0m",
- Boom::Color.red("Red!")
+ Boom::Color.red("Red!").should == "\e[31mRed!\e[0m"
end
it "yellow" do
- assert_equal "\e[33mYellow!\e[0m",
- Boom::Color.yellow("Yellow!")
+ Boom::Color.yellow("Yellow!").should == "\e[33mYellow!\e[0m"
end
it "cyan" do
- assert_equal "\e[36mCyan!\e[0m",
- Boom::Color.cyan("Cyan!")
+
+ Boom::Color.cyan("Cyan!").should == "\e[36mCyan!\e[0m"
end
end
View
93 spec/command_spec.rb
@@ -3,11 +3,11 @@
describe Boom::Command do
before do
- [Boom::Platform::Darwin, Boom::Platform::Linux,
- Boom::Platform::Windows].each do |klass|
+ [Boom::Platform::Darwin, Boom::Platform::Linux,
+ Boom::Platform::Windows].each do |klass|
klass.any_instance.stubs('system')
- end
- IO.stubs(:popen)
+ end
+ IO.stub(:popen)
boom_json :urls
end
@@ -22,30 +22,31 @@ def command(cmd)
it "use remote" do
response = command('remote the_office fun awesome')
- assert_match /a new list called the_office/, response
- assert_match /fun in the_office is awesome/, response
+ response.should =~ /a new list called the_office/
+ response.should =~ /fun in the_office is awesome/
end
it "remote checks for acceptable config" do
response = command('remote the_office fun awesome')
- assert_match /a new list called the_office/, response
- assert_match /fun in the_office is awesome/, response
+ response.should =~ /a new list called the_office/
+ response.should =~ /fun in the_office is awesome/
end
it "overview for empty" do
storage = Boom::Storage
storage.stubs(:lists).returns([])
Boom::Command.stubs(:storage).returns(storage)
- assert_match /have anything yet!/, command(nil)
+ command(nil).should =~ /have anything yet!/
end
it "overview" do
+ debugger
command(nil).should == ' urls (2)'
end
it "list detail" do
- assert_match /github/, command('urls')
+ command('urls').should =~ /github/
end
it "list all" do
@@ -55,19 +56,19 @@ def command(cmd)
end
it "list creation" do
- assert_match /a new list called newlist/, command('newlist')
+ command('newlist').should =~ /a new list called newlist/
end
it "list creation with item" do
- assert_match /a new list called newlist.* item in newlist/, command('newlist item blah')
+ command('newlist item blah').should =~ /a new list called newlist.* item in newlist/
end
it "list creation with item stdin" do
STDIN.stubs(:read).returns('blah')
STDIN.stubs(:stat)
STDIN.stat.stubs(:size).returns(4)
- assert_match /a new list called newlist.* item in newlist is blah/, command('newlist item')
+ command('newlist item').should =~ /a new list called newlist.* item in newlist is blah/
end
it "item access" do
@@ -83,15 +84,15 @@ def command(cmd)
end
it "item open item" do
- assert_match /opened https:\/\/github\.com for you/, command('open github')
+ command('open github').should =~ /opened https:\/\/github\.com for you/
end
it "item open specific item" do
- assert_match /opened https:\/\/github\.com for you/, command('open urls github')
+ command('open urls github').should =~ /opened https:\/\/github\.com for you/
end
it "item open lists" do
- assert_match /opened all of urls for you/, command('open urls')
+ command('open urls').should =~ /opened all of urls for you/
end
it "item creation" do
@@ -106,116 +107,114 @@ def command(cmd)
it "list deletion no" do
STDIN.stubs(:gets).returns('n')
- assert_match /Just kidding then/, command('urls delete')
+ command('urls delete').should =~ /Just kidding then/
end
it "list deletion yes" do
STDIN.stubs(:gets).returns('y')
- assert_match /Deleted all your urls/, command('urls delete')
+ command('urls delete').should =~ /Deleted all your urls/
end
it "item deletion" do
- assert_match /github is gone forever/, command('urls github delete')
+ command('urls github delete').should =~ /github is gone forever/
end
it "help" do
- assert_match 'boom help', command('help')
- assert_match 'boom help', command('-h')
- assert_match 'boom help', command('--help')
+ command('help').should =~ 'boom help'
+ command('-h').should =~ 'boom help'
+ command('--help').should =~ 'boom help'
end
it "noop options" do
- assert_match 'boom help', command('--anything')
- assert_match 'boom help', command('-d')
+ command('--anything').should =~ 'boom help'
+ command('-d').should =~ 'boom help'
end
it "nonexistent item access scoped by list" do
- assert_match /twitter not found in urls/, command('urls twitter')
+ command('urls twitter').should =~ /twitter not found in urls/
end
it "echo item" do
- assert_match %r{https://github\.com}, command('echo github')
+ command('echo github').should =~ %r{https://github\.com}
end
it "echo item shorthand" do
- assert_match %r{https://github\.com}, command('e github')
+ command('e github').should =~ %r{https://github\.com}
end
it "echo item does not exist" do
- assert_match /wrong.*not found/, command('echo wrong')
+ command('echo wrong').should =~ /wrong.*not found/
end
it "echo list item" do
- assert_match %r{https://github\.com}, command('echo urls github')
+ command('echo urls github').should =~ %r{https://github\.com}
end
it "echo list item does not exist" do
- assert_match /wrong not found in urls/, command('echo urls wrong')
+ command('echo urls wrong').should =~ /wrong not found in urls/
end
it "show storage" do
Boom::Config.any_instance.stubs(:attributes).returns('backend' => 'json')
- assert_match /You're currently using json/, command('storage')
+ command('storage').should =~ /You're currently using json/
end
it "nonexistant storage switch" do
Boom::Config.any_instance.stubs(:save).returns(true)
- assert_match /couldn't find that storage engine/, command('switch dkdkdk')
+ command('switch dkdkdk').should =~ /couldn't find that storage engine/
end
it "storage switch" do
Boom::Config.any_instance.stubs(:save).returns(true)
- assert_match /We've switched you over to redis/, command('switch redis')
+ command('switch redis').should =~ /We've switched you over to redis/
end
it "version switch" do
- assert_match /#{Boom::VERSION}/, command('-v')
+ command('-v').should =~ /#{Boom::VERSION}/
end
it "version long" do
- assert_match /#{Boom::VERSION}/, command('--version')
+ command('--version').should =~ /#{Boom::VERSION}/
end
it "stdin pipes" do
- stub = Object.new
- stub.stubs(:stat).returns([1,2])
- stub.stubs(:read).returns("http://twitter.com")
- Boom::Command.stubs(:stdin).returns(stub)
- assert_match /twitter in urls/, command('urls twitter')
+ stdin = mock 'stdin', :stat => [1,2], :read => "http://twitter.com"
+ Boom::Command.stub(:stdin).and_return stdin
+ command('urls twitter').should =~ /twitter in urls/
end
it "random" do
Boom::Config.any_instance.stubs(:save).returns(true)
- assert_match /opened .+ for you/, command('random')
+ command('random').should =~ /opened .+ for you/
end
it "random from list" do
Boom::Config.any_instance.stubs(:save).returns(true)
- assert_match /(github|zachholman)/, command('random urls')
+ command('random urls').should =~ /(github|zachholman)/
end
it "random list not exist" do
Boom::Config.any_instance.stubs(:save).returns(true)
- assert_match /couldn't find that list\./, command('random 39jc02jlskjbbac9')
+ command('random 39jc02jlskjbbac9').should =~ /couldn't find that list\./
end
it "delete item list not exist" do
- assert_match /couldn't find that list\./, command('urlz github delete')
+ command('urlz github delete').should =~ /couldn't find that list\./
end
it "delete item wrong list" do
command('urlz twitter https://twitter.com/')
- assert_match /github not found in urlz/, command('urlz github delete')
+ command('urlz github delete').should =~ /github not found in urlz/
end
it "delete item different name" do
command('foo bar baz')
- assert_match /bar is gone forever/, command('foo bar delete')
+ command('foo bar delete').should =~ /bar is gone forever/
end
it "delete item same name" do
command('duck duck goose')
- assert_match /duck is gone forever/, command('duck duck delete')
+ command('duck duck delete').should =~ /duck is gone forever/
end
end
View
6 spec/config_spec.rb
@@ -12,12 +12,12 @@
it "bootstraps config" do
@config.bootstrap
- @config.attributes.should == ({:backend => 'json'})
+ @config.should == ({:backend => 'json'})
end
it "attributes" do
- @config.attributes[:wu_tang] = 'clan'
- @config.attributes[:wu_tang].should == 'clan'
+ @config[:wu_tang] = 'clan'
+ @config[:wu_tang].should == 'clan'
end
View
16 spec/list_spec.rb
@@ -14,23 +14,23 @@
it "add items" do
@list.items.size.should == 0
- @list.add_item(@item)
+ @list.add(@item)
@list.items.size.should == 1
end
it "add item with duplicate name" do
- @list.add_item(@item)
+ @list.add(@item)
@list.items.size.should == 1
@list.find_item('github').value.should == 'https://github.com'
@diff_item = Boom::Item.new('github', 'https://github.com/home')
- @list.add_item(@diff_item)
+ @list.add(@diff_item)
@list.items.size.should == 1
@list.find_item('github').value.should == 'https://github.com/home'
end
it "to hash" do
@list.to_hash[@list.name].size.should == 0
- @list.add_item(@item)
+ @list.add(@item)
@list.to_hash[@list.name].size.should == 1
end
@@ -39,13 +39,13 @@
end
it "find item" do
- @list.add_item(@item)
+ @list.add(@item)
@list.find_item('github').value.should == 'https://github.com'
end
it "find item long name" do
@item = Boom::Item.new('long-long-long-name','longname')
- @list.add_item(@item)
+ @list.add(@item)
@list.find_item('long-long-long-').value.should == 'longname'
@list.find_item('long-long-long-…').value.should == 'longname'
end
@@ -63,11 +63,11 @@
end
it "deletes scoped to list" do
- @list.add_item(@item)
+ @list.add(@item)
@list_2 = Boom::List.new('sexy-companies')
@item_2 = Boom::Item.new(@item.name, @item.value)
- @list_2.add_item(@item_2)
+ @list_2.add(@item_2)
@list.delete_item(@item.name)
@list.items.size.should == 0
View
2 spec/remote_spec.rb
@@ -16,7 +16,7 @@ def dummy type
remote = [Boom::Storage::Gist, Boom::Storage::Mongodb, Boom::Storage::Redis]
(local + remote).all? do |type|
- Boom::Remote.allowed? dummy(type).should.not == nil
+ Boom::Remote.allowed? dummy(type).should_not be_nil
end
Boom.use_remote true
View
7 spec/spec_helper.rb
@@ -17,9 +17,8 @@
def boom_json(name)
root = File.expand_path(File.dirname(__FILE__))
- Boom::Storage::Json.any_instance.stubs(:save).returns(true)
- Boom::Storage::Json.any_instance.stubs(:json_file).
- returns("#{root}/examples/#{name}.json")
+ Boom::Storage::Json.any_instance.stub(:save).and_return(true)
+ Boom::Storage::Json.any_instance.stub(:json_file).and_return("#{root}/examples/#{name}.json")
Boom.use_remote false
- Boom.stubs(:storage).returns(Boom::Storage::Json.new)
+ Boom.stub(:storage).and_return Boom::Storage::Json.new
end
View
1 temp.txt
@@ -0,0 +1 @@
+asdf

0 comments on commit 48a9a7e

Please sign in to comment.
Something went wrong with that request. Please try again.