assert-view 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,16 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- assert-view (0.2.0)
4
+ assert-view (0.3.0)
5
+ ansi (~> 1.3)
5
6
  undies (~> 1.1)
6
7
 
7
8
  GEM
8
9
  remote: http://rubygems.org/
9
10
  specs:
10
11
  ansi (1.3.0)
11
- assert (0.4.0)
12
- ansi (~> 1.3)
13
- assert-view
12
+ assert (0.6.0)
13
+ assert-view (~> 0.3)
14
14
  rake (0.9.2)
15
15
  undies (1.1.0)
16
16
 
data/README.rdoc CHANGED
@@ -13,30 +13,34 @@ Assert::View is a dependency of Assert and will be automatically installed when
13
13
 
14
14
  $ gem install assert # will install assert-view as a dependency
15
15
 
16
- === Usage: override the default view with a different one
17
- Assert uses the Assert::View::Terminal view outputting to $stdout by default (https://github.com/teaminsight/assert/blob/master/lib/assert/setup/view.rb). To override and use a different view, add the following to your ~/.assert/options.rb file:
16
+ === Usage: the default view
17
+ Assert uses the Assert::View::DefaultView outputting to $stdout by default (https://github.com/teaminsight/assert/blob/master/lib/assert/setup/view.rb). To override and use a different view, add the following to your ~/.assert/options.rb file:
18
18
 
19
19
  require 'assert/view/different_view'
20
20
 
21
21
  # Override the Assert view option and assign it an instance of the different view
22
- # Setup the view passing it the suite accessor and the IO to output on
23
- Assert.options.view Assert::View::DifferentView.new(Assert.suite, $stdout)
22
+ # Setup the view passing it the IO to output on
23
+ Assert.options.view Assert::View::DifferentView.new($stdout)
24
24
 
25
25
  === Usage: define your own and override
26
26
  So, ~/.assert/option.rb is just a ruby script that is required when Assert is setting itself up. You can use this file to define your own custom view class and then override the Assert view option like above:
27
27
 
28
- # Say you wanted to tweak and make a better Terminal view
29
- require 'assert/view/terminal'
28
+ # Say you wanted to tweak and make a better DefaultView
29
+ require 'assert/view/default_view'
30
30
  module Assert::View
31
- class MyBetterTerminal < Terminal
31
+ class MyBetterDefaultView < DefaultView
32
32
  # override stuff and tweak it to your heart's content
33
33
  end
34
34
  end
35
35
 
36
36
  # Now override the view option to use your better terminal
37
- Assert.options.view Assert::View::MyBetterTerminal.new(Assert.suite, $stdout)
37
+ Assert.options.view Assert::View::MyBetterDefaultView.new($stdout)
38
38
 
39
39
 
40
+ You could also define an entirely new view from scratch. Look at the existing views and read the below about writing your own view for more details. Once you have written your new view, tell Assert to use it with the following:
41
+
42
+ Assert.options.view Assert::View::MyNewView.new($stdout)
43
+
40
44
 
41
45
  == Assert::View::Base class
42
46
  All views need to subclass the Assert::View::Base class. This class implements a few core things that assert expects of its view classes:
@@ -49,46 +53,67 @@ All view initializers take two things at minimum:
49
53
  === 'suite' reader
50
54
  The suite reader provides access to the suite of tests that will be or has been run. Use this reader to do things like count tests or test results, iterate through the tests and display detailed results, etc. This reader provides all the model data needed to render your view.
51
55
 
52
- === 'render' method
53
- The render method, as its name suggests, handles the overall rendering of the view. All render methods should take the following arguments:
54
- * *args*: not used right now - more for view backwards compatibility in the event that args are needed
55
- * *runner*: runner is a block that is given to the render method by the Assert::Runner class in use. The view class should call this block (@runner.call@) when the view is ready to run the suite of tests. Output any view headers before calling; output any view summary/footer after calling.
56
-
57
- Here is an excerpt from the Terminal class to illustrate how a render method could be implemented:
58
-
59
- def render(*args, &runner)
60
- self.io_puts(:load_stmt) # header info
61
-
62
- if count(:tests) > 0
63
- runner.call if runner # run the test suite
64
- self.io_puts(:detailed_results) # show any result details
65
- end
66
-
67
- self.io_puts(:results_stmt) # summary/footer info
68
- end
69
-
70
- === 'handle_runtime_result' method
71
- This method is called as the suite of tests is being run. It is a callback for when a new test result is added to a tests results and the result is passed as the only argument. Use of the method is totally optional. The Terminal view uses it to output result abbreviations while the test suite is running.
56
+ === The Renderer
57
+ The view renderer provided by the base class uses Undies (https://github.com/kelredd/undies) to define and render view templates. It mixes in a 'render' method to the base view that handles creating an Undies::Template from the view's template definition and wiring up the necessary runner callbacks.
72
58
 
73
59
  === Utilities
74
60
  The base class provides a few utilities for rendering views:
75
- * *io_puts*: puts output to the output IO. Pass it the string to output or a symbol of a method that returns the string to output.
76
- * *io_print*: same as io_puts, printing the string instead of putting it
77
61
  * *run_time*: get a string with the suite's run time in seconds
78
62
  * *run_seed*: get the seed value used to run the test suite in random order
79
63
  * *count*: helper method for counting stuff on the suite, ie: 'count(:tests)'
64
+ * etc... Check out the base class for all utilities (https://github.com/teaminsight/assert-view/blob/master/lib/assert/view/base.rb)
65
+
66
+ == Anatomy of a View
67
+
68
+ So I'd like to explain some key things about Assert views in detail to understand the anatomy of a view and hopefully help you understand how to create your own.
69
+
70
+ First off, all views need to subclass Assert::View::Base. The base class provides a bunch of utilities and handles all the necessary callbacks between a view and Assert's Runner class. In addition, the base class provides all methods necessary to render the view's template. Beyond that, a View has 3 main parts:
71
+ === 1 - Options
72
+ The base class mixes in Assert's options helpers so that options can be specified on any view. The base class provides a few key options:
73
+ * *default_passed_abbrev*: ["."] the default abbreviation for passed results
74
+ * *default_failed_abbrev*: ["F"] ditto for failed results
75
+ * *default_errored_abbrev*: ["E"] ditto for errored results
76
+ * *default_skipped_abbrev*: ["S"] ditto for skipped results
77
+ * *default_ignored_abbrev*: ["I"] ditto for ignored results
78
+
79
+ In addition, the DefaultView specifies a few options of its own:
80
+ * *styled*: [true] whether or not to show ansi-styled results, set to false for plain text output
81
+ * *passed_styles* [:green] the styles to markup passing result output with
82
+ * *failed_styles* [:red, :bold] ditto for failed result output
83
+ * *errored_styles* [:yellow, :bold] ditto for errored result output
84
+ * *skipped_styles* [:cyan] ditto for skipped result output
85
+ * *ignored_styles* [:magenta] ditto for ignored result output
86
+
87
+ Use options in your views to override the base default options or to define your own for tweaking behavior and customization.
88
+
89
+ === 2 - Template / Template Helpers
90
+ The base class provides a 'template' class method. Use this method to define an Undies template to render your view. Check out Undies for details on how to create an Undies template. Templates are given two locals to work with:
91
+ * *view*: this local refers to the instance of the view class. Use it to get data or run logic.
92
+ * *runner*: this is a block used to callback to Assert's runner and run the tests. Pass this local to the base 'run_tests' method to control when (in rendering your view) the tests are run. Optionally pass a block to 'run_tests' that will be called each time a new result is generated by the running tests. Use this to render live runtime result data.
93
+
94
+ If you need to define some helper methods for your view to use, add them to a helpers module (check out: https://github.com/teaminsight/assert-view/blob/master/lib/assert/view/helpers/ansi.rb). Use the 'helper' class method on your view to mix those helpers in to the view's template scope and then you can use them in your template.
95
+
96
+ === 3 - Data/Logic
97
+ Assert views encourage defining your view's data handling and business logic seperately from your view's template. Define instance methods on your view to access, process, and handle data and business logic. Your template can then access them using its 'view' local.
98
+
99
+
100
+
101
+ == Other Views
102
+ TODO: put in notes about other views available for use...
80
103
 
81
104
 
82
105
 
83
106
  == Roll Your Own!
84
107
 
85
- Assert::View is designed to be extended and customized. Using the Base class, create your own view classes and use them as you see fit. If you feel like sharing, fork the repo, and add a pull requests. Bonus points to anyone who rips off other testing frameworks views (LeftRight, Turn, etc.)
108
+ Check out the different views available here. Use a few and customize them using their options. If you find you can't see your test results how you like or you prefer the way an alternate testing library outputs test results, create your own view class. Write it inline in your '.assert/options.rb' file and hook it up with Assert's view option. If you want to share it with everyone, fork this gem, add it in, and submit a pull request.
109
+
110
+ TODO: put in guidlines for submitting new views...
86
111
 
87
112
 
88
113
 
89
114
  == License
90
115
 
91
- Copyright (c) 2011 Kelly D. Redding and Team Insight
116
+ Copyright (c) 2011 Kelly Redding and Team Insight
92
117
 
93
118
  Permission is hereby granted, free of charge, to any person
94
119
  obtaining a copy of this software and associated documentation
data/assert-view.gemspec CHANGED
@@ -20,5 +20,6 @@ Gem::Specification.new do |s|
20
20
  s.add_development_dependency("bundler")
21
21
  s.add_development_dependency("assert")
22
22
 
23
+ s.add_dependency("ansi", ["~> 1.3"])
23
24
  s.add_dependency("undies", ["~> 1.1"])
24
25
  end
@@ -1,9 +1,53 @@
1
1
  require 'assert/options'
2
- require 'assert/view/renderer'
3
2
 
4
3
  module Assert::View
5
4
 
5
+ # this module is mixed in to the Assert::View::Base class
6
+ # it use Undies to define and render view templates
7
+ module Renderer
8
+ require 'undies'
9
+
10
+ def self.included(receiver)
11
+ receiver.send(:extend, ClassMethods)
12
+ end
13
+
14
+ # define rendering template class to use for rendering
15
+ # need to overwrite the '_' and '__' meths to add trailing newlines
16
+ # b/c streaming output doesn't add any whitespace
17
+ class Template < ::Undies::Template
18
+
19
+ def _(data="", nl=true); super(data.to_s + (nl ? "\n" : "")); end
20
+ def __(data="", nl=true); super(data.to_s + (nl ? "\n" : "")); end
21
+
22
+ end
23
+
24
+ # this method is required by assert and is called by the test runner
25
+ # use Undies to render the template
26
+ # using the view's template file
27
+ # streaming to the view's output io
28
+ # passing in the view itself and any runner_callback as locals
29
+ def render(*args, &runner_callback)
30
+ locals = {
31
+ :view => self,
32
+ :runner => runner_callback
33
+ }
34
+ Template.new(self.output_io, locals, &self.class.template)
35
+ end
36
+
37
+ module ClassMethods
38
+
39
+ # make any helper methods available to the template
40
+ def helper(helper_klass)
41
+ Template.send(:include, helper_klass)
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+
48
+
6
49
  class Base
50
+
7
51
  include Assert::Options
8
52
  options do
9
53
  default_passed_abbrev '.'
@@ -19,6 +63,15 @@ module Assert::View
19
63
  # * 'self.helper': used to provide helper mixins to the renderer template
20
64
  include Renderer
21
65
 
66
+ # set the view's template by passing a block, get by calling w/ no args
67
+ def self.template(&block)
68
+ if block
69
+ @template = block
70
+ else
71
+ @template
72
+ end
73
+ end
74
+
22
75
  attr_accessor :suite, :output_io, :runtime_result_callback
23
76
 
24
77
  def initialize(output_io, suite=Assert.suite)
@@ -30,17 +83,6 @@ module Assert::View
30
83
  self
31
84
  end
32
85
 
33
-
34
-
35
- # TODO: look for files in the .assert dir
36
- # TODO: allow option for specifying which template to use
37
- # TODO: test
38
- def template_file
39
- File.expand_path("./templates/#{self.options.template}.rb", File.dirname(__FILE__))
40
- end
41
-
42
-
43
-
44
86
  # called by the view template
45
87
  # store off any result_callback
46
88
  # call the runner callback to actually run the tests
@@ -68,7 +110,6 @@ module Assert::View
68
110
  self.suite.count(type)
69
111
  end
70
112
 
71
- # TODO: test
72
113
  def tests?
73
114
  self.count(:tests) > 0
74
115
  end
@@ -1,10 +1,63 @@
1
1
  require 'assert/result'
2
2
  require 'assert/options'
3
+
3
4
  require 'assert/view/base'
5
+ require 'assert/view/helpers/ansi'
4
6
 
5
7
  module Assert::View
6
8
 
7
- class Terminal < Base
9
+ # This is the default view used by assert. It renders ansi test output
10
+ # designed for terminal viewing.
11
+
12
+ class DefaultView < Base
13
+ helper Helpers::AnsiStyles
14
+ options do
15
+ styled true
16
+ passed_styles :green
17
+ failed_styles :red, :bold
18
+ errored_styles :yellow, :bold
19
+ skipped_styles :cyan
20
+ ignored_styles :magenta
21
+ end
22
+
23
+ template do
24
+ __
25
+ __ view.loaded_tests_statement
26
+
27
+ if view.tests?
28
+
29
+ __ view.running_tests_statement
30
+
31
+ view.run_tests(runner) do |each_result|
32
+ result_sym = each_result.to_sym
33
+ result_abbrev = view.options.send("#{result_sym}_abbrev")
34
+ __ ansi_styled_msg(result_abbrev, result_ansi_styles(result_sym)), false
35
+ end
36
+ __ "\n" # add a newline after streamed runner output
37
+
38
+ view.detailed_results do |result, output|
39
+ __ ansi_styled_msg(result.to_s, result_ansi_styles(result))
40
+
41
+ if !output.empty?
42
+ __ view.result_output_start_msg
43
+ __ output, false
44
+ __ view.result_output_end_msg
45
+ end
46
+
47
+ __
48
+ end
49
+
50
+ end
51
+
52
+ # build a summary sentence w/ styled results breakdown
53
+ styled_results_breakdown_statement = view.results_breakdown_statement do |msg, result_type|
54
+ ansi_styled_msg(msg, result_ansi_styles(result_type))
55
+ end
56
+
57
+ __ [ view.result_count_statement, ": ", styled_results_breakdown_statement ].join('')
58
+ __
59
+ __ view.run_time_statement
60
+ end
8
61
 
9
62
  def loaded_tests_statement
10
63
  "Loaded suite (#{view.count(:tests)} test#{'s' if view.count(:tests) != 1})"
@@ -16,7 +69,7 @@ module Assert::View
16
69
 
17
70
  # show test details in reverse order from how they were collected (FILO)
18
71
  def detailed_tests
19
- @detailed_tests ||= self.suite.ordered_tests.reverse
72
+ self.suite.ordered_tests.reverse
20
73
  end
21
74
 
22
75
  # get all the results that have details to show
@@ -1,5 +1,5 @@
1
1
  module Assert; end
2
2
 
3
3
  module Assert::View
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -0,0 +1 @@
1
+ require 'assert/view'
data/test/base_test.rb CHANGED
@@ -14,7 +14,8 @@ module Assert::View
14
14
  subject{ @view }
15
15
 
16
16
  should have_accessors :suite, :output_io, :runtime_result_callback
17
- should have_instance_methods :template_file, :run_tests, :handle_runtime_result
17
+ should have_class_method :template
18
+ should have_instance_methods :run_tests, :handle_runtime_result
18
19
  should have_instance_methods :run_time, :runner_seed, :count, :tests?, :all_passed?
19
20
  should have_instance_methods :ocurring_result_types, :result_summary_msg
20
21
  should have_instance_methods :all_passed_result_summary_msg, :to_sentence
@@ -1,6 +1,6 @@
1
1
  require 'assert'
2
2
 
3
- require 'assert/view/terminal'
3
+ require 'assert/view/default_view'
4
4
  require 'stringio'
5
5
 
6
6
  module Assert::View
@@ -8,7 +8,7 @@ module Assert::View
8
8
  class TerminalTest < Assert::Context
9
9
  desc "the terminal view"
10
10
  setup do
11
- @view = Assert::View::Terminal.new(Assert::Suite.new, StringIO.new("", "w+"))
11
+ @view = Assert::View::DefaultView.new(Assert::Suite.new, StringIO.new("", "w+"))
12
12
  end
13
13
  subject{ @view }
14
14
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assert-view
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-08 00:00:00 Z
18
+ date: 2011-09-09 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :development
@@ -49,6 +49,21 @@ dependencies:
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ hash: 9
57
+ segments:
58
+ - 1
59
+ - 3
60
+ version: "1.3"
61
+ version_requirements: *id003
62
+ name: ansi
63
+ - !ruby/object:Gem::Dependency
64
+ type: :runtime
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
52
67
  none: false
53
68
  requirements:
54
69
  - - ~>
@@ -58,7 +73,7 @@ dependencies:
58
73
  - 1
59
74
  - 1
60
75
  version: "1.1"
61
- version_requirements: *id003
76
+ version_requirements: *id004
62
77
  name: undies
63
78
  description: A collection of views for use in the Assert testing framework
64
79
  email:
@@ -76,17 +91,16 @@ files:
76
91
  - README.rdoc
77
92
  - Rakefile
78
93
  - assert-view.gemspec
94
+ - lib/assert-view.rb
79
95
  - lib/assert/view.rb
80
96
  - lib/assert/view/base.rb
97
+ - lib/assert/view/default_view.rb
81
98
  - lib/assert/view/helpers/ansi.rb
82
- - lib/assert/view/renderer.rb
83
- - lib/assert/view/templates/assert.ansi.rb
84
- - lib/assert/view/terminal.rb
85
99
  - lib/assert/view/version.rb
86
100
  - test/base_test.rb
101
+ - test/default_view_test.rb
87
102
  - test/helper.rb
88
103
  - test/irb.rb
89
- - test/terminal_test.rb
90
104
  homepage: http://github.com/teaminsight/assert-view
91
105
  licenses: []
92
106
 
@@ -122,6 +136,6 @@ specification_version: 3
122
136
  summary: A collection of views for use in the Assert testing framework
123
137
  test_files:
124
138
  - test/base_test.rb
139
+ - test/default_view_test.rb
125
140
  - test/helper.rb
126
141
  - test/irb.rb
127
- - test/terminal_test.rb
@@ -1,45 +0,0 @@
1
- require 'undies'
2
-
3
- module Assert::View
4
-
5
- # this module is mixed in to the Assert::View::Base class
6
- # it use Undies to define and render view templates
7
- module Renderer
8
-
9
- def self.included(receiver)
10
- receiver.send(:extend, ClassMethods)
11
- end
12
-
13
- # define rendering template class to use for rendering
14
- # need to overwrite the '_' and '__' meths to add trailing newlines
15
- # b/c streaming output doesn't add any whitespace
16
- class Template < ::Undies::Template
17
-
18
- def _(data="", nl=true); super(data.to_s + (nl ? "\n" : "")); end
19
- def __(data="", nl=true); super(data.to_s + (nl ? "\n" : "")); end
20
-
21
- end
22
-
23
- # this method is required by assert and is called by the test runner
24
- # use Undies to render the template
25
- # using the view's template file
26
- # streaming to the view's output io
27
- # passing in the view itself and any runner_callback as locals
28
- def render(*args, &runner_callback)
29
- Template.new(File.expand_path(self.template_file), self.output_io, {
30
- :view => self,
31
- :runner => runner_callback
32
- })
33
- end
34
-
35
- module ClassMethods
36
-
37
- # make any helper methods available to the template
38
- def helper(helper_klass)
39
- Template.send(:include, helper_klass)
40
- end
41
-
42
- end
43
-
44
- end
45
- end
@@ -1,36 +0,0 @@
1
- __
2
- __ view.loaded_tests_statement
3
-
4
- if view.tests?
5
-
6
- __ view.running_tests_statement
7
-
8
- view.run_tests(runner) do |each_result|
9
- result_sym = each_result.to_sym
10
- result_abbrev = view.options.send("#{result_sym}_abbrev")
11
- __ ansi_styled_msg(result_abbrev, result_ansi_styles(result_sym)), false
12
- end
13
- __ "\n" # add a newline after streamed runner output
14
-
15
- view.detailed_results do |result, output|
16
- __ ansi_styled_msg(result.to_s, result_ansi_styles(result))
17
-
18
- if !output.empty?
19
- __ view.result_output_start_msg
20
- __ output, false
21
- __ view.result_output_end_msg
22
- end
23
-
24
- __
25
- end
26
-
27
- end
28
-
29
- # build a summary sentence w/ styled results breakdown
30
- styled_results_breakdown_statement = view.results_breakdown_statement do |msg, result_type|
31
- ansi_styled_msg(msg, result_ansi_styles(result_type))
32
- end
33
-
34
- __ [ view.result_count_statement, ": ", styled_results_breakdown_statement ].join('')
35
- __
36
- __ view.run_time_statement