radiant-autotest 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Josh French
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.rdoc ADDED
@@ -0,0 +1,31 @@
1
+ = radiant-autotest
2
+
3
+ Autotest mappings for running RSpec on your Radiant Extensions.
4
+ Includes Growl support, with delightful icons.
5
+
6
+ == Installation and Use
7
+
8
+ $ gem install jfrench-radiant-autotest
9
+ $ cd vendor/extensions/your_extension
10
+ $ autotest
11
+
12
+ If you have Growl and the growlnotify binary installed, you can enable Growl
13
+ notifications. To do so, create a file named .autotest in
14
+ vendor/extensions/your_extension and add this line:
15
+
16
+ require 'autotest/radiant/growl'
17
+
18
+ Growl can be downloaded from http://growl.info and includes growlnotify.
19
+
20
+ The gem provides two delightful icons to be displayed with your pass/fail
21
+ counts. If you would like to replace these with your own less delightful
22
+ icons, simply place two files named pass.png and fail.png in
23
+ vendor/extensions/your_extension/lib.
24
+
25
+ Happy testing!
26
+
27
+ === Copyright
28
+
29
+ Copyright (c) 2009 Josh French. See LICENSE for details.
30
+
31
+ Delightful icon design by IconBuffet: http://iconbuffet.com.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "radiant-autotest"
8
+ gem.summary = %Q{Autotest mappings for Radiant extensions}
9
+ gem.email = "josh@vitamin-j.com"
10
+ gem.homepage = "http://github.com/jfrench/radiant-autotest"
11
+ gem.authors = ["Josh French"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "radiant-autotest #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,4 @@
1
+ # Loads the Autotest::Radiant runner if it appears that we're inside a Radiant extension.
2
+ Autotest.add_discovery do
3
+ "radiant" if Dir.pwd =~ /vendor\/extensions/ && !Dir.glob('*_extension.rb').empty?
4
+ end
@@ -0,0 +1,101 @@
1
+ require 'autotest/rspec'
2
+
3
+ Autotest.add_hook :initialize do |at|
4
+ at.clear_mappings
5
+ at.add_exception(%r%^\.\/(?:cache|db|doc|log|public|script|tmp|vendor)%)
6
+
7
+ at.add_mapping(%r%^spec/(controllers|helpers|models|lib|views)/.*rb$%) do |filename,_|
8
+ filename
9
+ end
10
+
11
+ at.add_mapping(%r%spec/spec_helper\.rb%) do
12
+ at.files_matching %r%^spec/(controllers|helpers|lib|models|views)/.*_spec%
13
+ end
14
+
15
+ at.add_mapping(%r%^#{at.extension_name}_extension\.rb%) do |f,m|
16
+ at.files_matching %r%^spec/(controllers|helpers|lib|models|views)/.*_spec%
17
+ end
18
+
19
+ at.add_mapping(%r%^app/controllers/(.*)\.rb$%) do |_,match|
20
+ if match[1] == "#{at.extension_name}_controller"
21
+ at.files_matching %r%^spec/controllers/.*_spec\.rb$%
22
+ else
23
+ ["spec/controllers/#{match[1]}_spec.rb"]
24
+ end
25
+ end
26
+
27
+ at.add_mapping(%r%^app/helpers/(.*)_helper.rb%) do |_,match|
28
+ if match[1] == at.extension_name
29
+ at.files_matching %r%^spec/(helpers|views)/.*_spec\.rb$%
30
+ else
31
+ ["spec/controllers/#{match[1]}_controller_spec.rb",
32
+ "spec/helpers/#{match[1]}_helper_spec.rb",
33
+ "spec/views/#{match[1]}_view_spec.rb"]
34
+ end
35
+ end
36
+
37
+ at.add_mapping(%r%lib/.*([\w_])\.rb%) do |_,match|
38
+ at.files_matching(%r%^spec/.*#{match[1]}_spec\.rb%)
39
+ end
40
+
41
+ at.add_mapping(%r%^app/models/(.*)\.rb$%) do |_,match|
42
+ ["spec/models/#{match[1]}_spec.rb"]
43
+ end
44
+
45
+ at.add_mapping(%r%^app/views/([\w\/_]+)\.%) do |_,match|
46
+ ["spec/views/#{match[1]}_view_spec.rb"]
47
+ end
48
+ end
49
+
50
+ Autotest.add_hook :ran_command do |at|
51
+ at.results.grep at.count_re
52
+ at.examples_total, at.examples_failed, at.examples_pending = $1.to_i, $2.to_i, $3.to_i
53
+ end
54
+
55
+ # Although not declared as readable attributes, the examples_total,
56
+ # examples_failed, and examples_pending counts are available on the instance.
57
+ # This may be useful if you're implementing new notifications:
58
+ #
59
+ # Autotest.add_hook :ran_command do |at|
60
+ # logger.info "You have #{at.examples_pending} specs pending!"
61
+ # end
62
+ #
63
+ # Conscientious grammarians may wish to use the pluralization helper:
64
+ #
65
+ # Autotest.add_hook :waiting do |at|
66
+ # logger.info "You have #{at.spec_string at.examples_pending} pending!"
67
+ # end
68
+ class Autotest::Radiant < Autotest::Rspec
69
+ attr_reader :count_re
70
+ attr_writer :examples_total, :examples_failed, :examples_pending
71
+
72
+ def initialize #:nodoc:
73
+ super
74
+ @count_re = /(\d+) examples?, (\d+) failures?(?:, (\d+) pending)?/
75
+ end
76
+
77
+ # Return the number of passing specs, not including pending.
78
+ def success_count
79
+ examples_total - examples_pending - examples_failed
80
+ end
81
+
82
+ # Attr readers with special sauce to ensure initialization as integers.
83
+ %w(examples_total examples_failed examples_pending).each do |attr|
84
+ class_eval <<-EOS, __FILE__, __LINE__
85
+ def #{attr} # def examples_total
86
+ @#{attr} ||= 0 # @examples_total ||= 0
87
+ end # end
88
+ EOS
89
+ end
90
+
91
+ def extension_name
92
+ Dir.pwd.split('/').last
93
+ end
94
+
95
+ # Cheapie pluralization helper for use in notifications.
96
+ # Returns 'spec' or 'specs' based on the value of +n+.
97
+ def spec_string(n=1)
98
+ 1 == n ? "#{n} spec" : "#{n} specs"
99
+ end
100
+
101
+ end
@@ -0,0 +1,44 @@
1
+ # Additional Autotest hooks and notification methods for Growl integration.
2
+
3
+ require 'autotest/rspec'
4
+
5
+ class Autotest::Radiant < Autotest::Rspec
6
+
7
+ # Basic notification function. +pri+ = priority, which is used by Growl
8
+ # to tweak background color and other settings to help visually distinguish
9
+ # red/green notifications.
10
+ def growl title, msg, img, pri=0
11
+ system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title}"
12
+ end
13
+
14
+ # The image used in success notifications. Checks in local lib/ for
15
+ # pass.png; if none is found, defaults to the delightful smiley face.
16
+ def pass_img
17
+ local = File.expand_path(File.join(Dir.pwd, %w(lib pass.png)))
18
+ File.exists?(local) ? local : File.expand_path(File.join(__FILE__, %w(.. .. .. pass.png)))
19
+ end
20
+
21
+ # The image used in failure notifications. Checks in local lib/ for
22
+ # fail.png; if none is found, defaults to the delightful frowny face.
23
+ def fail_img
24
+ local = File.expand_path(File.join(Dir.pwd, %w(lib fail.png)))
25
+ File.exists?(local) ? local : File.expand_path(File.join(__FILE__, %w(.. .. .. fail.png)))
26
+ end
27
+
28
+ end
29
+
30
+ Autotest.add_hook :red do |at|
31
+ at.growl "Failure", "#{at.spec_string at.examples_failed} failed", at.fail_img, 2
32
+ end
33
+
34
+ Autotest.add_hook :green do |at|
35
+ msg = "#{at.spec_string at.success_count} passed"
36
+ msg += ", #{at.examples_pending} pending" if at.examples_pending > 0
37
+ at.growl "Success", msg, at.pass_img, -2 if at.tainted
38
+ end
39
+
40
+ Autotest.add_hook :all_good do |at|
41
+ msg = "#{at.spec_string at.success_count} passed"
42
+ msg += ", #{at.examples_pending} pending" if at.examples_pending > 0
43
+ at.growl "Success", msg, at.pass_img, -2 if at.tainted
44
+ end
data/lib/fail.png ADDED
Binary file
data/lib/pass.png ADDED
Binary file
@@ -0,0 +1,53 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{radiant-autotest}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Josh French"]
9
+ s.date = %q{2009-07-01}
10
+ s.email = %q{josh@digitalpulp.com}
11
+ s.summary = "Autotest runner for Radiant extensions"
12
+ s.description = "Autotest runner for Radiant extensions"
13
+ s.extra_rdoc_files = [
14
+ "LICENSE",
15
+ "README.rdoc"
16
+ ]
17
+ s.files = [
18
+ ".gitignore",
19
+ "LICENSE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "lib/autotest/discover.rb",
24
+ "lib/autotest/radiant.rb",
25
+ "lib/autotest/radiant/growl.rb",
26
+ "lib/fail.png",
27
+ "lib/pass.png",
28
+ "radiant-autotest.gemspec",
29
+ "spec/lib/radiant_autotest_spec.rb",
30
+ "spec/matchers/autotest_matchers.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/jfrench/radiant-autotest}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.3}
36
+ s.summary = %q{Autotest mappings for Radiant extensions}
37
+ s.test_files = [
38
+ "spec/lib/radiant_autotest_spec.rb",
39
+ "spec/matchers/autotest_matchers.rb"
40
+ ]
41
+ s.add_dependency 'ZenTest', '>= 3.9.0'
42
+ s.add_dependency 'rspec' # version mainly dependent on Radiant
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ else
50
+ end
51
+ else
52
+ end
53
+ end
@@ -0,0 +1,109 @@
1
+ require File.join(File.dirname(__FILE__), %w(.. .. lib autotest radiant))
2
+ require File.join(File.dirname(__FILE__), %w(.. matchers autotest_matchers))
3
+
4
+ describe Autotest::Radiant do
5
+ before do
6
+ Dir.stub!(:pwd).and_return('my') # stub name as my_extension
7
+ @autotest = Autotest::Radiant.new
8
+ @autotest.hook :initialize
9
+ end
10
+
11
+ it "should know which extension is running" do
12
+ @autotest.extension_name.should == 'my'
13
+ end
14
+
15
+ it "should initialize count attrs with 0" do
16
+ @autotest.examples_total.should == 0
17
+ @autotest.examples_pending.should == 0
18
+ @autotest.examples_failed.should == 0
19
+ end
20
+
21
+ it "should calculate successful specs" do
22
+ @autotest.examples_total = 10
23
+ @autotest.examples_pending = 3
24
+ @autotest.examples_failed = 2
25
+ @autotest.success_count.should == 5
26
+ end
27
+
28
+ describe "spec matchers" do
29
+ it "should map controller spec" do
30
+ @autotest.should map_specs(['spec/controllers/my_controller_spec.rb']).
31
+ to('spec/controllers/my_controller_spec.rb')
32
+ end
33
+
34
+ it "should map nested controller spec" do
35
+ @autotest.should map_specs(['spec/controllers/admin/my_controller_spec.rb']).
36
+ to('spec/controllers/admin/my_controller_spec.rb')
37
+ end
38
+
39
+ it "should map helper spec" do
40
+ @autotest.should map_specs(['spec/helpers/my_helper_spec.rb']).
41
+ to('spec/helpers/my_helper_spec.rb')
42
+ end
43
+
44
+ it "should map model spec" do
45
+ @autotest.should map_specs(['spec/models/my_model_spec.rb']).
46
+ to('spec/models/my_model_spec.rb')
47
+ end
48
+ end
49
+
50
+ # Assumption: my_extension, my_controller, my_helper are often parent classes
51
+ # for other concrete descendants
52
+ describe "extension matchers" do
53
+ it "should map extension.rb to all specs" do
54
+ @autotest.should map_specs(['spec/controllers/my_controller_spec.rb', 'spec/helpers/my_helper_spec.rb',
55
+ 'spec/lib/my_lib_spec.rb', 'spec/models/my_model_spec.rb', 'spec/views/my_view_spec.rb']).
56
+ to('my_extension.rb')
57
+ end
58
+
59
+ it "should map extension controller to all controller specs" do
60
+ @autotest.should map_specs(['spec/controllers/admin/another_controller_spec.rb', 'spec/controllers/my_controller_spec.rb']).
61
+ to('app/controllers/my_controller.rb')
62
+ end
63
+
64
+ it "should map extension helper to all controller and view specs" do
65
+ @autotest.should map_specs(['spec/helpers/sample_helper_spec.rb', 'spec/views/sample_view_spec.rb']).
66
+ to('app/helpers/my_helper.rb')
67
+ end
68
+ end
69
+
70
+ describe "application matchers" do
71
+ it "should map controller" do
72
+ @autotest.should map_specs(['spec/controllers/my_controller_spec.rb']).
73
+ to('app/controllers/my_controller.rb')
74
+ end
75
+
76
+ it "should map nested controller" do
77
+ @autotest.should map_specs(['spec/controllers/admin/my_controller_spec.rb']).
78
+ to('app/controllers/admin/my_controller.rb')
79
+ end
80
+
81
+
82
+
83
+ it "should map helper to controller, helper, and view specs" do
84
+ @autotest.should map_specs(['spec/controllers/sample_controller_spec.rb', 'spec/helpers/sample_helper_spec.rb',
85
+ 'spec/views/sample_view_spec.rb']).
86
+ to('app/helpers/sample_helper.rb')
87
+ end
88
+
89
+ it "should map lib to spec" do
90
+ @autotest.should map_specs(['spec/lib/lib_spec.rb']).
91
+ to('lib/lib.rb')
92
+ end
93
+
94
+ it "should map nested lib" do
95
+ @autotest.should map_specs(['spec/lib/lib_spec.rb']).
96
+ to('lib/nested/lib.rb')
97
+ end
98
+
99
+ it "should map model to spec" do
100
+ @autotest.should map_specs(['spec/models/model_spec.rb']).
101
+ to('app/models/model.rb')
102
+ end
103
+
104
+ it "should map view to spec" do
105
+ @autotest.should map_specs(['spec/views/samples/index_view_spec.rb']).
106
+ to('app/views/samples/index.anything')
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,38 @@
1
+ module Spec
2
+ module Matchers
3
+ class AutotestMappingMatcher
4
+ def initialize(specs)
5
+ @specs = specs
6
+ end
7
+
8
+ def to(file)
9
+ @file = file
10
+ self
11
+ end
12
+
13
+ def matches?(autotest)
14
+ @autotest = prepare(autotest)
15
+ @actual = autotest.test_files_for(@file)
16
+ @actual == @specs
17
+ end
18
+
19
+ def failure_message
20
+ "expected #{@autotest.class} to map #{@specs.inspect} to #{@file.inspect}\ngot #{@actual.inspect}"
21
+ end
22
+
23
+ private
24
+
25
+ def prepare(autotest)
26
+ find_order = @specs.dup << @file
27
+ autotest.instance_eval { @find_order = find_order }
28
+ autotest
29
+ end
30
+
31
+ end
32
+
33
+ def map_specs(specs)
34
+ AutotestMappingMatcher.new(specs)
35
+ end
36
+
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-autotest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Josh French
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-01 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ZenTest
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 3.9.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Autotest runner for Radiant extensions
36
+ email: josh@digitalpulp.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .gitignore
46
+ - LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION
50
+ - lib/autotest/discover.rb
51
+ - lib/autotest/radiant.rb
52
+ - lib/autotest/radiant/growl.rb
53
+ - lib/fail.png
54
+ - lib/pass.png
55
+ - radiant-autotest.gemspec
56
+ - spec/lib/radiant_autotest_spec.rb
57
+ - spec/matchers/autotest_matchers.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/jfrench/radiant-autotest
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.4
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Autotest mappings for Radiant extensions
86
+ test_files:
87
+ - spec/lib/radiant_autotest_spec.rb
88
+ - spec/matchers/autotest_matchers.rb