Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use rspec2, add basic channel mocking
- Loading branch information
Bruce Williams
committed
Aug 30, 2012
1 parent
3cfa0be
commit 6e3ef6a
Showing
8 changed files
with
203 additions
and
66 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
--color |
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,80 @@ | ||
begin | ||
require 'rspec' | ||
rescue LoadError | ||
require 'rubygems' | ||
require 'rspec' | ||
end | ||
begin | ||
require 'rspec/core/rake_task' | ||
rescue LoadError | ||
puts <<-EOS | ||
To use rspec for testing you must install rspec2 gem: | ||
gem install rspec | ||
EOS | ||
exit(0) | ||
end | ||
|
||
begin | ||
require 'jeweler' | ||
Jeweler::Tasks.new do |gem| | ||
gem.name = "twtail" | ||
gem.summary = "twitter tail based on search.twitter.com - works perfectly with crappy internet connections usually available at tech conferences" | ||
gem.description = "twitter tail based on search.twitter.com - works perfectly with crappy internet connections usually available at tech conferences" | ||
gem.email = "caffeine@gmail.com" | ||
gem.homepage = "http://github.com/caffo/twtail" | ||
gem.authors = ["rodrigo franco (caffo)"] | ||
gem.add_dependency "htmlentities", ">= 4.2.1" | ||
gem.add_dependency "simple-rss", ">= 1.2.2" | ||
gem.add_development_dependency 'rspec', '>= 2.11.0' | ||
end | ||
Jeweler::GemcutterTasks.new | ||
rescue LoadError | ||
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" | ||
end | ||
|
||
require 'rake/testtask' | ||
Rake::TestTask.new(:test) do |test| | ||
test.libs << 'lib' << 'test' | ||
test.pattern = 'test/**/test_*.rb' | ||
test.verbose = true | ||
end | ||
|
||
begin | ||
require 'rcov/rcovtask' | ||
Rcov::RcovTask.new do |test| | ||
test.libs << 'test' | ||
test.pattern = 'test/**/test_*.rb' | ||
test.verbose = true | ||
end | ||
rescue LoadError | ||
task :rcov do | ||
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov" | ||
end | ||
end | ||
|
||
task :test => :check_dependencies | ||
|
||
task :default => :test | ||
|
||
require 'rake/rdoctask' | ||
Rake::RDocTask.new do |rdoc| | ||
version = File.exist?('VERSION') ? File.read('VERSION') : "" | ||
|
||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = "twtail #{version}" | ||
rdoc.rdoc_files.include('README*') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end | ||
|
||
desc 'Default: run specs.' | ||
task :default => :spec | ||
|
||
desc "Run specs" | ||
RSpec::Core::RakeTask.new do |t| | ||
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default. | ||
end | ||
|
||
task :default do | ||
puts "\nAvailable tasks: #{Rake.application.tasks.to_a.join(', ')}" | ||
puts "Use rake -T for more info.\n\n" | ||
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 was deleted.
Oops, something went wrong.
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,10 +1,16 @@ | ||
begin | ||
require 'spec' | ||
require 'rspec' | ||
rescue LoadError | ||
require 'rubygems' | ||
gem 'rspec' | ||
require 'spec' | ||
require 'rspec' | ||
end | ||
|
||
$:.unshift(File.dirname(__FILE__) + '/../lib') | ||
require 'twtail' | ||
|
||
$testing = true | ||
|
||
Dir.glob(File.expand_path('../support/*.rb', __FILE__)) do |filename| | ||
require filename | ||
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,28 @@ | ||
shared_context "mock channel", :mock_channel => true do | ||
|
||
let(:channel) { StringIO.new } | ||
let(:error_channel) { StringIO.new } | ||
|
||
before do | ||
@old_channel = Twtail.channel | ||
Twtail.channel = channel | ||
@old_error_channel = Twtail.error_channel | ||
Twtail.error_channel = error_channel | ||
end | ||
|
||
after do | ||
Twtail.channel = @old_channel | ||
Twtail.error_channel = @old_error_channel | ||
end | ||
|
||
def output | ||
channel.rewind | ||
channel.read | ||
end | ||
|
||
def error_output | ||
error_channel.rewind | ||
error_channel.read | ||
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 |
---|---|---|
@@ -1,14 +1,23 @@ | ||
require File.dirname(__FILE__) + '/spec_helper.rb' | ||
|
||
describe "A call without parameters" do | ||
describe Twtail, 'execute', :mock_channel => true do | ||
|
||
context "without parameters" do | ||
before do | ||
Twtail.execute(nil) | ||
end | ||
it "should return the application usage" do | ||
Twtail.execute(nil).should == "Usage: twtail [xbox+live | from:caffo | '#barcamp']" | ||
error_output.should == "Usage: twtail [xbox+live | from:caffo | '#barcamp']\n" | ||
end | ||
end | ||
end | ||
|
||
describe "A call with a parameter" do | ||
it "should display some results" do | ||
DEBUG=true | ||
Twtail.execute("xbox").should ==~ /xbox/ | ||
context "with a parameter" do | ||
before do | ||
Twtail.execute("xbox") | ||
end | ||
it "should display some results" do | ||
output.should =~ /xbox/ | ||
end | ||
end | ||
end | ||
|
||
end |