why_test 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ test/tmp/
2
+ tmp/
3
+ pkg/*
4
+
5
+ .bundle
6
+ .rvmrc
7
+ .DS_Store
8
+ Gemfile.lock
9
+
10
+ *.rbc
11
+ *.gem
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.9.2
3
+ branches:
4
+ only:
5
+ - master
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in why_test.gemspec
4
+ gemspec
@@ -0,0 +1,24 @@
1
+ [![Build Status](https://secure.travis-ci.org/charlietanksley/why_test.png)](https://secure.travis-ci.org/charlietanksley/why_test.png)
2
+
3
+
4
+
5
+ # Why_test
6
+
7
+
8
+
9
+ Perhaps my least favorite part of setting up a new project is getting
10
+ the tests set up. I start projects infrequently enough (and play with
11
+ different test frameworks often enough), that I can never remember what
12
+ goes in the Rakefile for an Rspec test suite vs. one for Riot. If you
13
+ are using rails, you can often +rake rspec:install+ or whatever to get
14
+ everything set up. If you aren't using Rails, you have to resort to the
15
+ googles. Why_test takes the pain out of setting up your tests.
16
+
17
+ # Use
18
+
19
+ **Currently only works on Ruby 1.9.2.**
20
+
21
+ ```
22
+ gem install why_test
23
+ gem why_test riot
24
+ ```
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ desc "Run all tests"
5
+ task :test do
6
+ Rake::TestTask.new do |t|
7
+ t.libs << "test"
8
+ t.pattern = "test/**/*_test.rb"
9
+ t.verbose = false
10
+ end
11
+ end
12
+
13
+ task :default => :test
@@ -0,0 +1,32 @@
1
+ # To do
2
+
3
+ * Add better tests (find a way to test the generated code).
4
+ * Add more frameworks.
5
+ * Consider adding some switches (like --no-sample for no sample code, or
6
+ --one for Ruby 1.8 (v. 1.9)).
7
+
8
+ # So many frameworks!
9
+
10
+ ## For sure
11
+
12
+ * Lemon (really interesting linking of tests and methods)
13
+ * Testy (sample code doubles as a test suite)
14
+
15
+ ## Projects I might want to include
16
+
17
+ * Bacon (negative: it's basically just rspec, right?)
18
+ * Micronaut (negative: it adds some to rspec, but looks mostly like an
19
+ rspec clone)
20
+ * Zebra (one-line tests without extra 'comments'; problem: last updated
21
+ 2009?; second problem: depends on gems that don't exit or don't work
22
+ with 1.9.2.)
23
+ * https://github.com/rubyworks/microtest
24
+ * https://github.com/rubyworks/lime
25
+ * https://github.com/rubyworks/citron
26
+
27
+
28
+ ## Done
29
+
30
+ * Shindo (clear focus on return value; also apparently has a good
31
+ interactive mode)
32
+ * https://github.com/peterc/testrocket.git
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env ruby
2
+ # 1.9 adds realpath to resolve symlinks; 1.8 doesn't
3
+ # have this method, so we add it so we get resolved symlinks
4
+ # and compatibility
5
+ unless File.respond_to? :realpath
6
+ class File #:nodoc:
7
+ def self.realpath path
8
+ return realpath(File.readlink(path)) if symlink?(path)
9
+ path
10
+ end
11
+ end
12
+ end
13
+ $: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib')
14
+ require 'rubygems'
15
+ require 'gli'
16
+ #require 'version'
17
+ require 'why_test'
18
+
19
+ include GLI
20
+
21
+ program_desc 'Generate test setup files and rake tasks'
22
+
23
+ version WhyTest::VERSION
24
+
25
+ #desc 'Describe some switch here'
26
+ #switch [:s,:switch]
27
+
28
+ #desc 'Describe some flag here'
29
+ #default_value 'the default'
30
+ #arg_name 'The name of the argument'
31
+ #flag [:f,:flagname]
32
+
33
+ desc 'An extremely fast, expressive, and context-driven unit-testing framework. Protest the slow test.'
34
+ #arg_name 'Describe arguments to rspec here'
35
+ command :riot do |c|
36
+ #c.desc 'Describe a switch to rspec'
37
+ #c.switch :s
38
+
39
+ #c.desc 'Describe a flag to rspec'
40
+ #c.default_value 'default'
41
+ #c.flag :f
42
+ c.action do |global_options,options,args|
43
+ dir = Dir.pwd
44
+ g = Generator.new('riot')
45
+ g.write_files(dir)
46
+
47
+ # Your command logic here
48
+
49
+ # If you have any errors, just raise them
50
+ # raise "that command made no sense"
51
+ end
52
+ end
53
+
54
+ desc 'BDD for Ruby.'
55
+ #arg_name 'Describe arguments to rspec here'
56
+ command :rspec do |c|
57
+ c.action do |global_options,options,args|
58
+ dir = Dir.pwd
59
+ g = Generator.new('rspec')
60
+ g.write_files(dir)
61
+ end
62
+ end
63
+
64
+ desc 'Work with your tests, not against them.'
65
+ command :shindo do |c|
66
+ c.action do |global_options,options,args|
67
+ dir = Dir.pwd
68
+ g = Generator.new('shindo')
69
+ g.write_files(dir)
70
+ end
71
+ end
72
+
73
+ desc 'Super simple Ruby testing library.'
74
+ command :testrocket do |c|
75
+ c.action do |global_options,options,args|
76
+ dir = Dir.pwd
77
+ g = Generator.new('testrocket')
78
+ g.write_files(dir)
79
+ end
80
+ end
81
+
82
+
83
+
84
+
85
+ pre do |global,command,options,args|
86
+ # Pre logic here
87
+ # Return true to proceed; false to abourt and not call the
88
+ # chosen command
89
+ # Use skips_pre before a command to skip this block
90
+ # on that command only
91
+ true
92
+ end
93
+
94
+ post do |global,command,options,args|
95
+ # Post logic here
96
+ # Use skips_post before a command to skip this
97
+ # block on that command only
98
+ end
99
+
100
+ on_error do |exception|
101
+ # Error logic here
102
+ # return false to skip default error handling
103
+ true
104
+ end
105
+
106
+ exit GLI.run(ARGV)
@@ -0,0 +1,3 @@
1
+ module WhyTest
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,2 @@
1
+ require "version"
2
+ require 'why_test/generator'
@@ -0,0 +1,70 @@
1
+ class Generator
2
+
3
+ attr_reader :directory
4
+
5
+ def initialize(framework)
6
+ @details = create(framework)
7
+ end
8
+
9
+ # Creates a hash with the relevant information for generating our
10
+ # testing files.
11
+ #
12
+ # @param [String] the name of a testing framework
13
+ # @return [Hash] hash with keys for framework name (:framework), files
14
+ # to be created (:files), and the rakefile (:rakfile).
15
+ def create(framework_name)
16
+ results = Hash[:framework => framework_name, :directories => [],
17
+ :files => [], :rakefile => 'Rakefile']
18
+
19
+ dir = File.join(File.dirname(File.expand_path(__FILE__)), 'generators', framework_name)
20
+ Dir.chdir dir
21
+ Dir["**/*"].each do |f|
22
+ results[:files].push f unless f == 'Rakefile' or File.directory? f
23
+ results[:directories].push f if File.directory? f
24
+ end
25
+
26
+ results
27
+ end
28
+
29
+ # Write the files.
30
+ #
31
+ # @param [String] the name of a root directory (default is current
32
+ # directory)
33
+ def write_files(root_directory='.')
34
+ base_dir = File.expand_path root_directory
35
+ @template_directory = File.join(File.dirname(__FILE__), 'generators', @details[:framework])
36
+
37
+ system "mkdir -p #{base_dir}" unless File.exists?(base_dir)
38
+ Dir.chdir base_dir
39
+
40
+ create_rakefile
41
+ create_directories
42
+ write_test_files
43
+ end
44
+
45
+
46
+ private
47
+
48
+ def create_rakefile
49
+ rakefile_contents = File.open(File.join(@template_directory, @details[:rakefile])) { |f| f.read }
50
+ File.open('Rakefile', 'a') do |f|
51
+ f.write rakefile_contents
52
+ end
53
+ end
54
+
55
+ def create_directories
56
+ @details[:directories].each do |d|
57
+ system "mkdir -p #{d}"
58
+ end
59
+ end
60
+
61
+ def write_test_files
62
+ @details[:files].each do |f|
63
+ file_contents = File.open(File.join(@template_directory, f)) { |c| c.read }
64
+ File.open(f, 'w') do |f|
65
+ f.write file_contents
66
+ end
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,12 @@
1
+ require 'rake/testtask'
2
+
3
+ desc "Run all our tests"
4
+ task :test do
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.pattern = "test/**/*_test.rb"
8
+ t.verbose = false
9
+ end
10
+ end
11
+
12
+ task :default => :test
@@ -0,0 +1,8 @@
1
+ require 'teststrap'
2
+
3
+ context "Sample string reverse" do
4
+ setup { 'this' }
5
+
6
+ asserts(:reverse).equals 'siht'
7
+ end
8
+
@@ -0,0 +1,3 @@
1
+ $:.unshift(File.dirname(__FILE__) + "/../lib/")
2
+ require 'rubygems'
3
+ require 'riot'
@@ -0,0 +1,9 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ desc 'Default: run specs.'
4
+ task :default => :spec
5
+
6
+ desc "Run specs"
7
+ RSpec::Core::RakeTask.new do |t|
8
+ t.pattern = "spec/**/*_spec.rb"
9
+ end
@@ -0,0 +1,5 @@
1
+ describe String do
2
+ it 'reverses a string' do
3
+ 'string'.reverse.should == 'gnirts'
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'rspec'
@@ -0,0 +1,13 @@
1
+ require 'rake/testtask'
2
+
3
+ desc "Run all our tests"
4
+ task :test do
5
+ system "shindont"
6
+ end
7
+
8
+ desc "Run tests in interactive mode"
9
+ task :testi do
10
+ system "shindo"
11
+ end
12
+
13
+ task :default => :test
@@ -0,0 +1,11 @@
1
+ # https://github.com/geemus/shindo
2
+ # try `shindo -array_tag` to ignore any tests with that tag, and
3
+ # `shindo +array_tag` to only run that test.
4
+
5
+ Shindo.tests('string manipulation', 'string_tag') do
6
+ returns('gnirts') { 'string'.reverse }
7
+ end
8
+
9
+ Shindo.tests('array manipulation', 'array_tag') do
10
+ returns(1) { [1].first }
11
+ end
@@ -0,0 +1,3 @@
1
+ $:.unshift(File.dirname(__FILE__) + "/../lib/")
2
+ require 'rubygems'
3
+ require 'shindo'
@@ -0,0 +1,12 @@
1
+ require 'rake/testtask'
2
+
3
+ desc "Run all our tests"
4
+ task :test do
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.pattern = "test/**/*_test.rb"
8
+ t.verbose = false
9
+ end
10
+ end
11
+
12
+ task :default => :test
@@ -0,0 +1,20 @@
1
+ # https://github.com/peterc/testrocket
2
+
3
+ # # USAGE
4
+ # +-> { block that should succeed }
5
+ # --> { block that should fail }
6
+ #
7
+ ## These two tests will deliberately fail
8
+ #+-> { raise }
9
+ #--> { true }
10
+ #
11
+ ## A 'pending' test
12
+ #~-> { "this is a pending test" }
13
+ #
14
+ ## A description
15
+ #!-> { "use this for descriptive output and to separate your test parts" }
16
+
17
+ require 'test_helper'
18
+
19
+ +-> { 'string'.reverse == 'gnirts' }
20
+ --> { 'string'.reverse == 'string' }
@@ -0,0 +1,2 @@
1
+ $:.unshift(File.dirname(__FILE__) + "/../lib/")
2
+ require 'testrocket'
@@ -0,0 +1,39 @@
1
+ #require 'tmpdir'
2
+ require 'teststrap'
3
+ require 'why_test/generator'
4
+
5
+ context "#create" do
6
+ setup { Generator.new('riot') }
7
+
8
+ asserts(:create, 'riot').equals Hash[:framework => 'riot', :directories => ['test'],
9
+ :files => ['test/sample_test.rb', 'test/teststrap.rb'], :rakefile => 'Rakefile']
10
+ end
11
+
12
+ context "#write_files" do
13
+ helper(:tmp_dir) do
14
+ File.join(File.expand_path(File.dirname(__FILE__)), 'tmp', 'temp')
15
+ end
16
+
17
+ setup do
18
+ Generator.new('riot').write_files(tmp_dir)
19
+ tmp_dir
20
+ end
21
+
22
+ teardown { system "rm -r -f #{tmp_dir}" }
23
+
24
+ context "it creates the directories we need" do
25
+ asserts{ File.exists?(File.join(topic, 'test')) }.equals true
26
+ asserts{ File.directory?(File.join(topic, 'test')) }.equals true
27
+ end
28
+
29
+ context "it creates a Rakefile" do
30
+ asserts{ File.exists?(File.join(topic, 'Rakefile')) }.equals true
31
+ end
32
+
33
+ context "it creates the files we need" do
34
+ asserts{ File.exists?(File.join(topic, 'test', 'teststrap.rb')) }.equals true
35
+ asserts{ File.exists?(File.join(topic, 'test', 'sample_test.rb')) }.equals true
36
+ end
37
+ end
38
+
39
+
@@ -0,0 +1,7 @@
1
+ require 'teststrap'
2
+
3
+ context "just a sample" do
4
+ setup { 'this' }
5
+
6
+ asserts(:reverse).equals 'siht'
7
+ end
@@ -0,0 +1,3 @@
1
+ $:.unshift(File.dirname(__FILE__) + "/../lib/")
2
+ require 'rubygems'
3
+ require 'riot'
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require File.join([File.dirname(__FILE__),'lib','version.rb'])
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "why_test"
7
+ s.version = WhyTest::VERSION
8
+ s.authors = ["Charlie Tanksley"]
9
+ s.email = ["charlie.tanksley@gmail.com"]
10
+ s.homepage = "http://github.com/charlietanksley/why_test"
11
+ s.summary = %q{Test setup generation}
12
+ s.description = %q{why_test is a command line utility that generates basic test setups for a number of different test frameworks.}
13
+
14
+ s.rubyforge_project = "why_test"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency('gli')
22
+ s.add_development_dependency('rake')
23
+ s.add_development_dependency('riot')
24
+ s.add_development_dependency('rspec')
25
+ s.add_development_dependency('shindo')
26
+ s.add_development_dependency('testrocket')
27
+
28
+ end
@@ -0,0 +1,5 @@
1
+ = why_test
2
+
3
+ Generate this with
4
+ why_test rdoc
5
+ After you have described your command line interface
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: why_test
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Charlie Tanksley
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-07 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gli
16
+ requirement: &2152972760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2152972760
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &2152972320 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2152972320
36
+ - !ruby/object:Gem::Dependency
37
+ name: riot
38
+ requirement: &2152971900 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2152971900
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &2152971420 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2152971420
58
+ - !ruby/object:Gem::Dependency
59
+ name: shindo
60
+ requirement: &2152970980 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2152970980
69
+ - !ruby/object:Gem::Dependency
70
+ name: testrocket
71
+ requirement: &2152970520 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2152970520
80
+ description: why_test is a command line utility that generates basic test setups for
81
+ a number of different test frameworks.
82
+ email:
83
+ - charlie.tanksley@gmail.com
84
+ executables:
85
+ - why_test
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - .gitignore
90
+ - .travis.yml
91
+ - Gemfile
92
+ - README.markdown
93
+ - Rakefile
94
+ - TODO.markdown
95
+ - bin/why_test
96
+ - lib/version.rb
97
+ - lib/why_test.rb
98
+ - lib/why_test/generator.rb
99
+ - lib/why_test/generators/riot/Rakefile
100
+ - lib/why_test/generators/riot/test/sample_test.rb
101
+ - lib/why_test/generators/riot/test/teststrap.rb
102
+ - lib/why_test/generators/rspec/Rakefile
103
+ - lib/why_test/generators/rspec/spec/sample_spec.rb
104
+ - lib/why_test/generators/rspec/spec/spec_helper.rb
105
+ - lib/why_test/generators/shindo/Rakefile
106
+ - lib/why_test/generators/shindo/tests/sample_tests.rb
107
+ - lib/why_test/generators/shindo/tests/test_helper.rb
108
+ - lib/why_test/generators/testrocket/Rakefile
109
+ - lib/why_test/generators/testrocket/test/sample_test.rb
110
+ - lib/why_test/generators/testrocket/test/test_helper.rb
111
+ - test/generator_test.rb
112
+ - test/sample_test.rb
113
+ - test/teststrap.rb
114
+ - why_test.gemspec
115
+ - why_test.rdoc
116
+ homepage: http://github.com/charlietanksley/why_test
117
+ licenses: []
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project: why_test
136
+ rubygems_version: 1.8.8
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: Test setup generation
140
+ test_files:
141
+ - test/generator_test.rb
142
+ - test/sample_test.rb
143
+ - test/teststrap.rb