inline_testing 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,4 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "riot", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.7)
10
+ rcov (0.9.9)
11
+ riot (0.12.3)
12
+ rr
13
+ rr (1.0.2)
14
+
15
+ PLATFORMS
16
+ x86-mingw32
17
+
18
+ DEPENDENCIES
19
+ bundler (~> 1.0.0)
20
+ jeweler (~> 1.5.2)
21
+ rcov
22
+ riot
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Ryan Lewis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # inline_testing
2
+
3
+ The name says it all.
4
+
5
+ Check out `examples/simple.rb`.
6
+
7
+ ## Contributing to inline_testing
8
+
9
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
10
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
11
+ * Fork the project
12
+ * Start a feature/bugfix branch
13
+ * Commit and push until you are happy with your contribution
14
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
15
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
16
+
17
+ ## Copyright
18
+
19
+ Copyright (c) 2011 Ryan Lewis. See LICENSE.txt for
20
+ further details.
21
+
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'psych'
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require 'rake'
12
+
13
+ require 'jeweler'
14
+ Jeweler::Tasks.new do |gem|
15
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
16
+ gem.name = "inline_testing"
17
+ gem.homepage = "http://github.com/c00lryguy/inline_testing"
18
+ gem.license = "MIT"
19
+ gem.summary = %Q{The name says it all.}
20
+ gem.description = %Q{Test from within your code}
21
+ gem.email = "c00lryguy@gmail.com"
22
+ gem.authors = ["Ryan Lewis"]
23
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
24
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
25
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
26
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/*_test.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/*_test.rb'
41
+ test.verbose = true
42
+ end
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "inline_testing #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,36 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
+ require 'inline_testing'
3
+ InlineTesting.init(__FILE__)
4
+
5
+ class User
6
+ attr_accessor :name, :email
7
+ def initialize(name, email)
8
+ @name, @email = name, email
9
+ end
10
+ end
11
+
12
+ InlineTesting.start(__LINE__)
13
+
14
+ my_user = User.new("Ryan", "c00lryguy@gmail.com")
15
+ # some ignored comment
16
+ my_user.name # => "Ryan"
17
+ my_user.email # => "c00lryguy@gmail.com"
18
+
19
+ InlineTesting.stop(__LINE__)
20
+ InlineTesting.test(binding)
21
+
22
+ class UserList < Array
23
+ def create_new(name, email)
24
+ self << User.new(name, email)
25
+ end
26
+ end
27
+
28
+ InlineTesting.start(__LINE__)
29
+
30
+ users = UserList.new
31
+ users.create_new("James", "jbones1234567@james.org")
32
+ users.create_new("Joe", "joejoejoejoe@four_joes.info")
33
+ users.sort.collect { |u| u.name } # => ["Joe", "James"]
34
+
35
+ InlineTesting.stop(__LINE__)
36
+ InlineTesting.test(binding)
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{inline_testing}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ryan Lewis"]
12
+ s.date = %q{2011-04-25}
13
+ s.description = %q{Test from within your code}
14
+ s.email = %q{c00lryguy@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "examples/simple.rb",
28
+ "inline_testing-0.1.0.gem",
29
+ "inline_testing.gemspec",
30
+ "lib/inline_testing.rb",
31
+ "test/inline_testing_test.rb",
32
+ "test/teststrap.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/c00lryguy/inline_testing}
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.7}
38
+ s.summary = %q{The name says it all.}
39
+ s.test_files = [
40
+ "examples/simple.rb",
41
+ "test/inline_testing_test.rb",
42
+ "test/teststrap.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<riot>, [">= 0"])
51
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
53
+ s.add_development_dependency(%q<rcov>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<riot>, [">= 0"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
58
+ s.add_dependency(%q<rcov>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<riot>, [">= 0"])
62
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
64
+ s.add_dependency(%q<rcov>, [">= 0"])
65
+ end
66
+ end
67
+
@@ -0,0 +1,33 @@
1
+
2
+ module InlineTesting
3
+ def self.init(filename)
4
+ @filename, @init = filename, true
5
+ end
6
+ def self.start(line_number)
7
+ @start_line_number = line_number
8
+ end
9
+ def self.stop(line_number)
10
+ if @init
11
+ @data = File.open(@filename).readlines[@start_line_number..line_number]
12
+ @start_line_number = nil
13
+ end
14
+ end
15
+ private
16
+ Regex = /^\x20*(.+)\x20*#\x20*=>\x20*(.+)\x20*$/
17
+ def self.test(binding)
18
+ puts "+-" * 40
19
+ if @init && @data
20
+ @data.find_all { |line| line =~ Regex }.each_with_index do |line, i|
21
+ code, result = line.match(Regex).captures
22
+ string_output = {
23
+ true => "Passed!",
24
+ false => "Failed!"
25
+ }
26
+ # All we need is to be able to eval the `code` within the context of the source file
27
+ assertion = eval(code, binding) == eval(result)
28
+ puts "#{i}: " + string_output[assertion]
29
+ end
30
+ @data = nil
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ require 'teststrap'
2
+
3
+ context "inline_testing" do
4
+ setup do
5
+ false
6
+ end
7
+
8
+ asserts "i'm a failure :(" do
9
+ topic
10
+ end
11
+ end
data/test/teststrap.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'riot'
11
+ require 'inline_testing'
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inline_testing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ prerelease: false
10
+ platform: ruby
11
+ authors:
12
+ - Ryan Lewis
13
+ autorequire: !!null
14
+ bindir: bin
15
+ cert_chain: []
16
+ date: 2011-04-25 00:00:00.000000000 -04:00
17
+ default_executable: !!null
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: riot
21
+ requirement: &21995640 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ segments:
28
+ - 0
29
+ type: :development
30
+ prerelease: false
31
+ version_requirements: *21995640
32
+ - !ruby/object:Gem::Dependency
33
+ name: bundler
34
+ requirement: &21994992 !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: 1.0.0
40
+ segments:
41
+ - 1
42
+ - 0
43
+ - 0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *21994992
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &21994356 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.5.2
55
+ segments:
56
+ - 1
57
+ - 5
58
+ - 2
59
+ type: :development
60
+ prerelease: false
61
+ version_requirements: *21994356
62
+ - !ruby/object:Gem::Dependency
63
+ name: rcov
64
+ requirement: &21993744 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ segments:
71
+ - 0
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: *21993744
75
+ description: Test from within your code
76
+ email: c00lryguy@gmail.com
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files:
80
+ - LICENSE.txt
81
+ - README.md
82
+ files:
83
+ - .document
84
+ - Gemfile
85
+ - Gemfile.lock
86
+ - LICENSE.txt
87
+ - README.md
88
+ - Rakefile
89
+ - VERSION
90
+ - examples/simple.rb
91
+ - inline_testing-0.1.0.gem
92
+ - inline_testing.gemspec
93
+ - lib/inline_testing.rb
94
+ - test/inline_testing_test.rb
95
+ - test/teststrap.rb
96
+ has_rdoc: true
97
+ homepage: http://github.com/c00lryguy/inline_testing
98
+ licenses:
99
+ - MIT
100
+ post_install_message: !!null
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ segments:
111
+ - 0
112
+ hash: 702226109
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ segments:
120
+ - 0
121
+ requirements: []
122
+ rubyforge_project: !!null
123
+ rubygems_version: 1.3.7
124
+ signing_key: !!null
125
+ specification_version: 3
126
+ summary: The name says it all.
127
+ test_files:
128
+ - examples/simple.rb
129
+ - test/inline_testing_test.rb
130
+ - test/teststrap.rb