fakeout 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/README.textile ADDED
@@ -0,0 +1,65 @@
1
+ h1. Fakeout
2
+
3
+ Fakeout helps you test your command line libraries. It captures all output to @STDOUT@ and @STDERR@ during test execution so you can ensure your library is yelling the right things at the user.
4
+
5
+ h2. Install
6
+
7
+ gem install fakeout
8
+
9
+ h2. RSpec
10
+
11
+ h3. Activate (before) and Deactivate (after) In All Specs
12
+
13
+ bc.. require "fakeout/spec_helpers"
14
+
15
+ RSpec.config do |c|
16
+ c.include Fakeout::SpecHelpers
17
+ end
18
+
19
+ h3. Only Certain Specs
20
+
21
+ bc.. require "fakeout/spec_helpers"
22
+
23
+ describe "Something" do
24
+ include Fakeout::SpecHelpers
25
+ end
26
+
27
+ h3. Manually Activate and Deactivate
28
+
29
+ bc.. require "fakeout/spec_helpers"
30
+
31
+ describe "Something" do
32
+ include Fakeout::SpecHelpers
33
+
34
+ before { Fakeout.activate! }
35
+ after { Fakeout.deactivate! }
36
+ end
37
+
38
+ h2. Test::Unit
39
+
40
+ bc.. # something_test.rb
41
+ require "fakeout/test_helpers"
42
+
43
+ class SomethingTest < Test::Unit::TestCase
44
+ include Fakeout::TestHelpers
45
+
46
+ def setup
47
+ Fakeout.activate!
48
+ end
49
+
50
+ def teardown
51
+ Fakeout.deactivate!
52
+ end
53
+ end
54
+
55
+ h2. Helpers
56
+
57
+ Fakeout exposes two string-like objects:
58
+
59
+ @stdout@ : Anything sent to @$stdout@.
60
+ @stderr@ : Anything sent to @$stderr@.
61
+
62
+ bc.. it "should write output" do
63
+ thing.that_outputs_to_stdout
64
+ stdout.should include "ohai"
65
+ end
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new
6
+
7
+ require "rake/testtask"
8
+ Rake::TestTask.new("test") do |t|
9
+ t.pattern = 'test/*_test.rb'
10
+ t.verbose = true
11
+ t.warning = true
12
+ end
13
+
14
+ task :default => [:spec, :test]
data/fakeout.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "fakeout/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "fakeout"
7
+ s.version = Fakeout::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Matte Noble"]
10
+ s.email = ["me@mattenoble.com"]
11
+ s.homepage = "http://github.com/mnoble/fakeout"
12
+ s.summary = %q{Fakeout captures STDOUT and STDERR for command line testing.}
13
+ s.description = %q{Fakeout captures STDOUT and STDERR for command line testing.}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency "rspec", ">= 2.5.0"
21
+ end
@@ -0,0 +1,19 @@
1
+ module Fakeout
2
+ class << self; attr_accessor :stdout, :stderr end
3
+
4
+ def self.activate!
5
+ $stdout = @stdout = StringIO.new
6
+ $stderr = @stderr = StringIO.new
7
+ @is_active = true
8
+ end
9
+
10
+ def self.deactivate!
11
+ $stdout = STDOUT
12
+ $stderr = STDERR
13
+ @is_active = false
14
+ end
15
+
16
+ def self.is_active?
17
+ @is_active
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ require "fakeout/test_helpers"
2
+
3
+ module Fakeout
4
+ module SpecHelpers
5
+ include TestHelpers
6
+
7
+ def self.extended(spec)
8
+ spec.fakeout(spec)
9
+ end
10
+
11
+ def self.included(spec)
12
+ spec.extend(self)
13
+ end
14
+
15
+ def fakeout(spec)
16
+ spec.before { Fakeout.activate! }
17
+ spec.after { Fakeout.deactivate! }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ require "fakeout"
2
+
3
+ module Fakeout
4
+ module TestHelpers
5
+ def stdout
6
+ Fakeout.stdout.string
7
+ end
8
+
9
+ def stderr
10
+ Fakeout.stderr.string
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Fakeout
2
+ VERSION = "0.0.1"
3
+ end
data/lib/fakeout.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "stringio"
2
+ require "fakeout/base"
@@ -0,0 +1,65 @@
1
+ require "rspec"
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require "fakeout"
4
+ require "fakeout/spec_helpers"
5
+
6
+ describe Fakeout do
7
+ before { Fakeout.activate! }
8
+ after { Fakeout.deactivate! }
9
+
10
+ it { should respond_to :activate! }
11
+ it { should respond_to :deactivate! }
12
+ it { should respond_to :is_active? }
13
+
14
+ it "should be active when activated" do
15
+ Fakeout.should be_is_active
16
+ end
17
+
18
+ it "should be inactive when deactivated" do
19
+ Fakeout.deactivate!
20
+ Fakeout.should_not be_is_active
21
+ end
22
+
23
+ describe ".activate!" do
24
+ it "should make $stdout a StringIO object" do
25
+ $stdout.should be_a StringIO
26
+ end
27
+
28
+ it "should make $stderr a StringIO object" do
29
+ $stderr.should be_a StringIO
30
+ end
31
+ end
32
+
33
+ describe ".deactivate!" do
34
+ before do
35
+ Fakeout.activate!
36
+ Fakeout.deactivate!
37
+ end
38
+
39
+ it "should put back the original $stdout" do
40
+ $stdout.should_not be_a StringIO
41
+ end
42
+
43
+ it "should put back the original $stderr" do
44
+ $stderr.should_not be_a StringIO
45
+ end
46
+ end
47
+
48
+ describe "spec_helpers" do
49
+ include Fakeout::SpecHelpers
50
+ subject { self }
51
+
52
+ it { should respond_to :stdout }
53
+ it { should respond_to :stderr }
54
+
55
+ it "should capture output to stdout" do
56
+ puts "omg output!"
57
+ stdout.should include "omg output!"
58
+ end
59
+
60
+ it "should capture output into stderr" do
61
+ $stderr.puts "errorz zomg!"
62
+ stderr.should include "errorz zomg!"
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,34 @@
1
+ require "test/unit"
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require "fakeout"
4
+ require "fakeout/test_helpers"
5
+
6
+ class FakeoutTest < Test::Unit::TestCase
7
+ include Fakeout::TestHelpers
8
+
9
+ def setup
10
+ Fakeout.activate!
11
+ end
12
+
13
+ def teardown
14
+ Fakeout.deactivate!
15
+ end
16
+
17
+ def test_responds_to_stdout
18
+ assert self.respond_to?(:stdout)
19
+ end
20
+
21
+ def test_responds_to_stderr
22
+ assert self.respond_to?(:stderr)
23
+ end
24
+
25
+ def test_captures_output_to_stdout
26
+ puts "is this thing on?"
27
+ assert_match("is this thing on?", stdout)
28
+ end
29
+
30
+ def test_captures_output_to_stderr
31
+ $stderr.puts "NOPE"
32
+ assert_match("NOPE", stderr)
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fakeout
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Matte Noble
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-29 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.5.0
24
+ type: :development
25
+ version_requirements: *id001
26
+ description: Fakeout captures STDOUT and STDERR for command line testing.
27
+ email:
28
+ - me@mattenoble.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - .gitignore
37
+ - Gemfile
38
+ - README.textile
39
+ - Rakefile
40
+ - fakeout.gemspec
41
+ - lib/fakeout.rb
42
+ - lib/fakeout/base.rb
43
+ - lib/fakeout/spec_helpers.rb
44
+ - lib/fakeout/test_helpers.rb
45
+ - lib/fakeout/version.rb
46
+ - spec/fakeout_spec.rb
47
+ - test/fakeout_test.rb
48
+ homepage: http://github.com/mnoble/fakeout
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.7.2
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Fakeout captures STDOUT and STDERR for command line testing.
75
+ test_files:
76
+ - spec/fakeout_spec.rb
77
+ - test/fakeout_test.rb