rspec 0.5.11 → 0.5.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/CHANGES +12 -0
  2. data/README +4 -2
  3. data/Rakefile +14 -4
  4. data/bin/spec +7 -7
  5. data/bin/test2spec +13 -8
  6. data/lib/spec/api/helper/diff.rb +53 -0
  7. data/lib/spec/api/helper/instance_helper.rb +11 -11
  8. data/lib/spec/api/helper/instance_negator.rb +11 -11
  9. data/lib/spec/api/helper/kind_helper.rb +11 -11
  10. data/lib/spec/api/helper/kind_negator.rb +11 -11
  11. data/lib/spec/api/helper/respond_helper.rb +11 -11
  12. data/lib/spec/api/helper/respond_negator.rb +11 -11
  13. data/lib/spec/api/helper/should_base.rb +6 -6
  14. data/lib/spec/api/helper/should_helper.rb +35 -35
  15. data/lib/spec/api/helper/should_negator.rb +20 -20
  16. data/lib/spec/rake/spectask.rb +15 -6
  17. data/lib/spec/runner.rb +1 -0
  18. data/lib/spec/runner/backtrace_tweaker.rb +2 -0
  19. data/lib/spec/runner/base_text_formatter.rb +3 -1
  20. data/lib/spec/runner/html_formatter.rb +153 -0
  21. data/lib/spec/runner/option_parser.rb +9 -2
  22. data/lib/spec/runner/progress_bar_formatter.rb +4 -0
  23. data/lib/spec/runner/rdoc_formatter.rb +3 -0
  24. data/lib/spec/runner/reporter.rb +5 -5
  25. data/lib/spec/runner/specdoc_formatter.rb +3 -0
  26. data/lib/spec/test_to_spec/sexp_transformer.rb +1 -0
  27. data/lib/spec/test_to_spec/translation_test_runner.rb +10 -2
  28. data/lib/spec/version.rb +1 -1
  29. data/test/spec/api/helper/arbitrary_predicate_test.rb +49 -73
  30. data/test/spec/api/helper/diff_test.rb +60 -0
  31. data/test/spec/api/helper/equality_test.rb +14 -0
  32. data/test/spec/api/helper/should_have_test.rb +0 -29
  33. data/test/spec/api/helper/typing_test.rb +87 -87
  34. data/test/spec/api/sugar_test.rb +0 -6
  35. data/test/spec/runner/backtrace_tweaker_test.rb +8 -2
  36. data/test/spec/runner/html_formatter_test.rb +47 -0
  37. data/test/spec/runner/option_parser_test.rb +0 -5
  38. data/test/test_classes.rb +73 -0
  39. data/test/test_helper.rb +3 -0
  40. metadata +8 -49
  41. data/doc/README +0 -3
  42. data/doc/config.yaml +0 -2
  43. data/doc/plugin/syntax.rb +0 -60
  44. data/doc/plugin/version.rb +0 -19
  45. data/doc/src/core_team.page +0 -31
  46. data/doc/src/default.css +0 -199
  47. data/doc/src/default.template +0 -31
  48. data/doc/src/documentation/index.page +0 -188
  49. data/doc/src/documentation/meta.info +0 -22
  50. data/doc/src/documentation/mocks.page +0 -287
  51. data/doc/src/documentation/underscores.page +0 -21
  52. data/doc/src/examples.page +0 -9
  53. data/doc/src/images/David_and_Aslak.jpg +0 -0
  54. data/doc/src/images/Whats_That_Dude.jpg +0 -0
  55. data/doc/src/images/ducks1.png +0 -0
  56. data/doc/src/images/ul.gif +0 -0
  57. data/doc/src/index.page +0 -74
  58. data/doc/src/meta.info +0 -33
  59. data/doc/src/tools/index.page +0 -49
  60. data/doc/src/tools/meta.info +0 -18
  61. data/doc/src/tools/rails.page +0 -132
  62. data/doc/src/tools/rake.page +0 -21
  63. data/doc/src/tools/rcov.page +0 -28
  64. data/doc/src/tools/spec.page +0 -129
  65. data/doc/src/tools/test2spec.page +0 -103
  66. data/doc/src/tutorials/index.page +0 -52
  67. data/doc/src/tutorials/meta.info +0 -36
  68. data/doc/src/tutorials/notes.txt +0 -263
  69. data/doc/src/tutorials/stack.rb +0 -11
  70. data/doc/src/tutorials/stack_01.page +0 -226
  71. data/doc/src/tutorials/stack_02.page +0 -182
  72. data/doc/src/tutorials/stack_03.page +0 -283
  73. data/doc/src/tutorials/stack_04.page +0 -164
  74. data/doc/src/tutorials/stack_04.page.orig +0 -123
  75. data/doc/src/tutorials/stack_05.page +0 -90
  76. data/doc/src/tutorials/stack_05.page.orig +0 -124
  77. data/doc/src/tutorials/stack_06.page +0 -359
  78. data/doc/src/tutorials/stack_06.page.orig +0 -359
  79. data/doc/src/tutorials/stack_spec.rb +0 -25
  80. data/doc/src/ul.gif +0 -0
@@ -1,21 +0,0 @@
1
- ---
2
- title: Underscore sugar
3
- inMenu: true
4
- ---
5
- h2. Underscore sugar
6
-
7
- The internal implementation of RSpec actually uses chained method calls, so it's possible
8
- to write:
9
-
10
- <ruby>
11
- lambda { 1.should.not.equal 1 }.should.raise
12
- </ruby>
13
-
14
- However, in order to make RSpec look and feel closer to other ruby code,
15
- RSpec allows you to use underscores instead if you wish:
16
-
17
- <ruby>
18
- lambda { 1.should_not_equal 1 }.should_raise
19
- </ruby>
20
-
21
- Therefore, you will see the underscored syntax throughout the documentation and examples.
@@ -1,9 +0,0 @@
1
- ---
2
- title: Examples
3
- inMenu: true
4
- ---
5
- h2. Examples
6
-
7
- Here is an example of an RSpec spec:
8
-
9
- <ruby file="../examples/stack_spec.rb" />
Binary file
Binary file
@@ -1,74 +0,0 @@
1
- ---
2
- title: Overview
3
- inMenu: true
4
- ---
5
-
6
- h2. Behaviour Driven Development
7
-
8
- Test Driven Development (TDD) has you define the behaviour of your system by
9
- writing small tests that precisely define some small piece of your system's
10
- behaviour. Then you implement that behaviour. Then you clean up & improve your
11
- design.
12
-
13
- At least that's how you're supposed to do it.
14
-
15
- This focus on behaviour is the real value in TDD, and marks the genuinely
16
- experienced TDD practitioner.
17
-
18
- However, with the ubiquity of testing related terminology in TDD and it's
19
- supporting frameworks, it is no surprise that it takes beginners some time to
20
- get to the understanding that TDD isn't about testing at all... if they ever
21
- do.
22
-
23
- The aim of BDD is to address this shortcoming and, by using terminology
24
- focused on the behavioural aspects of the system rather than testing, attempt
25
- to help direct developers towards a focus on the real value to be found in TDD
26
- at its most successful, or BDD as we call it.
27
-
28
- (paraphrased from "behaviour-driven.org":http://behaviour-driven.org)
29
-
30
- Dan North, who was the first to coin the term BDD, and who has been actively
31
- refining it since, started promoting BDD in 2003. "JBehave":http://jbehave.codehaus.org/
32
- was the first BDD framework to support this new thinking.
33
-
34
- h2. RSpec
35
-
36
- RSpec is a framework for practicing __Behaviour Driven Development__ (BDD) in Ruby.
37
-
38
- It all started with a blogpost
39
- ("A New Look at Test Driven Development":http://blog.daveastels.com/articles/2005/07/05/a-new-look-at-test-driven-development)
40
- of Dave's where he talked about his ideas for BDD and a BDD framework. One thing he mentioned was that his ideas
41
- would be easily implemented in Smalltalk, and probably Ruby.
42
-
43
- Steven Baker wrote the first version of the rspec core. Dave added mock support (initially inspired from Schmock by
44
- Ben Griffiths). Dave and David had met & talked about BDD at Agile'05 just after Dave's blog
45
- post (above). David started thinking about a BDD framework in C#. As fate, or
46
- the gods, would have it Dave & David ended up working at the same client in
47
- the greater Chicago area, allowing them to explore some ideas resulting in the totally rewriting of the expectation mechanism.
48
- Aslak joined in and the three rewrote the higher level syntax and the core, reworking RSpec into what you see now:
49
-
50
- <ruby>
51
- context "BDD framework" do
52
-
53
- setup do
54
- @bdd_framework = BddFramework.new
55
- end
56
-
57
- specify "should be adopted quickly" do
58
- @bdd_framework.should_be_adopted_quickly
59
- end
60
-
61
- specify "should be intuitive" do
62
- @bdd_framework.should_be_intuitive
63
- end
64
-
65
- end
66
- </ruby>
67
-
68
- RSpec provides a framework for writing what we call __executable
69
- specifications of program behaviour__. Since that's rather wordy, we usually
70
- just call them __specs__.
71
- "Some other people":http://www.testing.com/cgi-bin/blog/2006/04/12#spec-vs-example call these things __examples__.
72
-
73
- On this site you will find examples, documentation, and tutorials as well as
74
- links to download and community resources.
@@ -1,33 +0,0 @@
1
- index.page:
2
- orderInfo: 1
3
-
4
- examples.page:
5
- orderInfo: 2
6
-
7
- tutorials:
8
- title: Tutorial
9
- orderInfo: 5
10
-
11
- documentation:
12
- title: Documentation
13
- orderInfo: 6
14
-
15
- download.html:
16
- title: Download
17
- inMenu: true
18
- dest: http://rubyforge.org/frs/?group_id=797
19
- orderInfo: 7
20
-
21
- tools:
22
- title: Tools
23
- orderInfo: 8
24
-
25
- core_team.page:
26
- orderInfo: 9
27
-
28
- community.html:
29
- title: Community
30
- inMenu: true
31
- dest: http://rubyforge.org/projects/rspec
32
- orderInfo: 10
33
-
@@ -1,49 +0,0 @@
1
- ---
2
- title: Seven tools in one
3
- inMenu: true
4
- ---
5
-
6
- h2. Seven tools in one
7
-
8
- RSpec combines several tools in one...
9
-
10
- h3. 1) A language for expressing behavior
11
-
12
- RSpec provides programmers with a domain specific language for defining expected behavior of Ruby code.
13
-
14
- h3. 2) A runner for verifying behavior
15
-
16
- RSpec provides a command line utility for executing behavior specifications.
17
-
18
- h3. 3) Mock objects
19
-
20
- Mock objects frameworks usually come as separate add-ons to existing XUnit frameworks. In RSpec it's an integrated
21
- part of the framework.
22
-
23
- h3. 4) Testdox-like reports
24
-
25
- Expressing behavior in real sentences improves communication between programmer,
26
- analysts and testers. It also helps programmers keep a more critical mind about the code being developed.
27
-
28
- RSpec's built in support for generating "testdox-like":http://agiledox.sourceforge.net/ reports makes the code's behavior more transparent
29
- to everybody (assuming you publish it to a webpage where everybody who needs to can see it).
30
-
31
- h3. 5) Coverage tool
32
-
33
- While coverage tools cannot prove that you have verified everything there is to verify about your code,
34
- they can prove when you have not verified everything there is to verify about your code. RCov is such a
35
- coverage tool, and RSpec supportws it out-of the box via its Rake task.
36
-
37
- h3. 6) Coverage threshold verification
38
-
39
- Except for the times when programmers agree to keep a close eye on coverage and keep it at, say 90%, it
40
- will inevitably drop when they get other things to think about and start to write code in the wild.
41
-
42
- RSpec ships with a special Rake task that can verify that the coverage remains on a level defined by the
43
- development team. Should the coverage drop, the build will fail, and developers are encouraged to address
44
- it right away.
45
-
46
- h3. 7) Test::Unit translation
47
-
48
- Did you invest a lot of time in writing Test::Unit tests and want to switch to RSpec? Try out the test2spec
49
- tool, which will do most of the translation for you. (test2spec tool is experimental)
@@ -1,18 +0,0 @@
1
- index.page:
2
- orderInfo: 10
3
-
4
- spec.page:
5
- orderInfo: 11
6
-
7
- rake.page:
8
- orderInfo: 12
9
-
10
- rcov.page:
11
- orderInfo: 13
12
-
13
- test2spec.page:
14
- orderInfo: 14
15
-
16
- rails.page:
17
- orderInfo: 15
18
-
@@ -1,132 +0,0 @@
1
- ---
2
- title: RSpec on Rails
3
- inMenu: true
4
- ---
5
- h2. RSpec on Rails
6
-
7
- RSpec's rspec_generator Rubygem brings RSpec to Rails.
8
-
9
- h3. Features
10
-
11
- * Integrated fixture loading
12
- * Uses many of the controller-test integration features
13
- * Special generators for models and controllers that generate specs instead of tests.
14
-
15
- h3. Installation
16
-
17
- RSpec support for rails lives in a separate gem. Install that gem:
18
-
19
- <pre>
20
- gem install rspec_generator
21
- </pre>
22
-
23
- Once the gem is installed, you must configure you Rails app. Stand in the root of your Rails app and run:
24
-
25
- <pre>
26
- ruby script/generate rspec
27
- </pre>
28
-
29
- Now, you can generate models and controllers in a similar fashion to Rails' builtin generators. Example:
30
-
31
- <pre>
32
- ruby script/generate rspec_model person
33
- </pre>
34
-
35
- or
36
-
37
- <pre>
38
- ruby script/generate rspec_controller person
39
- </pre>
40
-
41
- For more information on each generator, just run them without any arguments.
42
-
43
- h3. Running specs
44
-
45
- All specs can be run with
46
-
47
- <pre>
48
- rake spec
49
- </pre>
50
-
51
- Model specs can be run with
52
-
53
- <pre>
54
- rake spec:models
55
- </pre>
56
-
57
- Controller specs can be run with
58
-
59
- <pre>
60
- rake spec:controllers
61
- </pre>
62
-
63
- To see all the RSpec related tasks, run
64
-
65
- <pre>
66
- rake --tasks spec
67
- </pre>
68
-
69
- h3. Naming conventions
70
-
71
- When you use Rails without RSpec (with Test::Unit), tests for models end up in tests/unit and tests for controllers
72
- end up in tests/functional.
73
-
74
- In order to make things more consistent, RSpec chooses a slightly different naming convention for direcotries and
75
- Rake tasks. So you will find model specs under specs/models, and controller specs under specs/controllers. The
76
- Rake tasks are named accordingly.
77
-
78
- h3. Examples
79
-
80
- RSpec on Rails adds several methods to your specs with a look and feel similar to Test::Unit. Example:
81
-
82
- Model:
83
- <ruby file="../vendor/rspec_on_rails/spec/models/person_spec.rb"/>
84
-
85
- Controller:
86
- <ruby file="../vendor/rspec_on_rails/spec/controllers/person_controller_spec.rb"/>
87
-
88
- h3. Translating existing Test::Unit tests
89
-
90
- The test2spec tool that ships with RSpec translates existing tests into RSpec specs.
91
- Translating tests to specs in a Rails environment requires some manual steps...
92
-
93
- h4. Install the rspec_generator
94
- How to do this is described above
95
-
96
- h4. Modify your test/test_helper.rb
97
- In order to be able to translate any Rails tests, you must modify your test/test_helper.rb file:
98
- <pre>
99
- # This line must be commented out in order for test2spec to work.
100
- # require 'test_help'
101
- require 'test2spec_help'
102
- </pre>
103
-
104
- The reason for this is that the <tt>test_help</tt> mixin confuses test2spec to the point
105
- where it's unable to perform the translation. The <tt>test2spec_help</tt> addresses this
106
- shortcoming.
107
-
108
- h4. Perform the translations
109
- Now you can translate your unit tests (model tests) with:
110
- <pre>
111
- test2spec --template spec/test2spec.erb --specdir spec/models test/unit
112
- </pre>
113
- and your functional tests (controller tests) with:
114
- <pre>
115
- test2spec --template spec/test2spec.erb --specdir spec/controllers test/functional
116
- </pre>
117
-
118
- h4. Edit your translated specs
119
- test2spec currently doesn't translate class-level statements such as <tt>fixtures</tt>, so you have to do this yourself.
120
- Copy all the <tt>fixtures</tt> statements in your tests to the corresponding contexts. Example:
121
-
122
- <ruby>
123
- context "The Foo Model" do
124
- fixtures :foo
125
- end
126
- </ruby>
127
-
128
- h4. Make sure fixtures are found.
129
- By default, RSpec on Rails expects to find fixtures under <tt>spec/fixtures</tt>. You should either move your
130
- existing <tt>test/fixtures/*.yml</tt> files to <tt>spec/fixtures</tt> or edit your <tt>spec/spec_helper.rb</tt>
131
- to point to the old <tt>test/fixtures</tt> location. Beware that every time you do a <tt>script/generate rspec_model</tt>,
132
- new fixstures will always be written to <tt>spec/fixtures</tt>.
@@ -1,21 +0,0 @@
1
- ---
2
- title: Rake Task
3
- inMenu: true
4
- ---
5
- h2. Rake Task
6
-
7
- RSpec comes with a Rake task for executing specs.
8
- See "Spec::Rake::SpecTask":../rdoc/classes/Spec/Rake/SpecTask.html for details.
9
-
10
- h3. Run specs
11
-
12
- <ruby file="../test/tasks/examples.rake"/>
13
-
14
- Also see the "RCov":rcov.html page for info about how to generate a coverage report.
15
-
16
- h3. Generate specdocs
17
-
18
- <ruby file="../test/tasks/examples_specdoc.rake"/>
19
-
20
- This will output the specdocs to a file, which can be included in your RDoc.
21
- Just like "this":../rdoc/files/EXAMPLES_rd.html.
@@ -1,28 +0,0 @@
1
- ---
2
- title: RCov
3
- inMenu: true
4
- ---
5
- h2. RCov
6
-
7
- RSpec has tight integration with "RCov":http://eigenclass.org/hiki.rb?rcov=.
8
-
9
- h3. Run specs with RCov
10
-
11
- <ruby file="../test/tasks/examples_with_rcov.rake"/>
12
-
13
- By adding rcov=true to the rake task, specs will be run with rcov
14
- instead of ruby, and a coverage report like "this":../coverage/index.html will be generated.
15
-
16
- See "Spec::Rake::SpecTask":../rdoc/classes/Spec/Rake/SpecTask.html for details.
17
-
18
- h3. Coverage threshold
19
-
20
- You can guard your codebase's coverage from dropping below a certain threshold
21
- by using RSpec's built-in task for verification of the total RCov coverage.
22
-
23
- <ruby file="../test/tasks/rcov_verify.rake"/>
24
-
25
- This will give you a :rcov_verify task that will fail your build if the
26
- coverage drops below the threshold you define (the higher the better).
27
-
28
- See "RCov::VerifyTask":../rdoc/classes/RCov/VerifyTask.html for details.
@@ -1,129 +0,0 @@
1
- ---
2
- title: Spec Runner
3
- inMenu: true
4
- ---
5
-
6
- h2. Executing specs directly
7
-
8
- Every RSpec context can be run directly from the command line:
9
-
10
- <pre>
11
- ruby path/to/my_spec.rb [options]
12
- </pre>
13
-
14
- This will print the results to STDOUT. Use the --help option for more details. This is
15
- practical when you only want to run one context. If you want to run more, use the spec tool
16
- or the Rake task. It should also be noted that the exitcode will always be 0 when run in standalone mode.
17
-
18
- h2. The spec command line
19
-
20
- After you install RSpec, you should have the spec command line tool on your PATH.
21
- This tool can be used to process several RSpec contexts in one go.
22
-
23
- spec will exit with the exitcode 1 if one or more specs fail.
24
-
25
- The general form of the command is
26
-
27
- <pre>
28
- spec [options] (FILE|DIRECTORY|GLOB)+
29
- </pre>
30
-
31
- Any number of files, directories and shell globs can be provided, all ruby source files
32
- that are found are loaded. Running spec on the previous example results in:
33
-
34
- <pre>
35
- bin/spec examples
36
- {execute: ruby ../bin/spec ../examples}
37
- </pre>
38
-
39
- Very simple and to the point. Passing specifications are indicated by a '.',
40
- failing ones by a 'F'. Note that failure indicates a violated expectation as
41
- well as an unexpected exception being raised. Here's an example with a failing specification:
42
-
43
- <pre>
44
- bin/spec failing_examples/stack_spec.rb
45
- {execute: ../bin/spec ../failing_examples/stack_spec.rb}
46
- </pre>
47
-
48
- In this case, the context is named "An almost full stack (with one item less than capacity)"
49
- and the specification is named "should return top when sent pop". These two are concatenated
50
- on the first line of the backtrace.
51
-
52
- h2. Command line options
53
-
54
- Additional command line options can be passed to customize the output and behaviour of RSpec.
55
- The following options apply whether specs are run in standalone mode (by executing the .rb files directly),
56
- or using the spec command.
57
-
58
- h3. -f, --format [specdoc|s|rdoc|r|]
59
-
60
- Specify the output format. Default format is "progress bar" ("." for pass, "F" for fail). Most formats will produce some form of "testdox":http://agiledox.sourceforge.net/
61
- output. The --dry-run options may also affect the output format.
62
-
63
- For example, by setting the formatter to rdoc, we can output the kind of input that RDoc
64
- needs to produce something like "this":../rdoc/files/EXAMPLES_rd.html
65
- <pre>
66
- $ bin/spec failing_examples/team_spec.rb -f rdoc
67
-
68
- {execute: ../bin/spec ../failing_examples/team_spec.rb -f rdoc}
69
- </pre>
70
-
71
- h4. Custom formatters
72
-
73
- As of RSpec 0.5.7 custom formatters are supported. If the argument to the --format option is none
74
- of the builtin formatters, RSpec will assume it's a class name, and try to instantiate that class.
75
- If you're using this feature, make sure to use the --require option as well - *before* the
76
- --format option.
77
-
78
- See the RDoc for "Spec::Runner::BaseTextFormatter":../rdoc/classes/Spec/Runner/BaseTextFormatter.html
79
- for details on how to implement your own. A custom formatter can be found under examples/custom_formatter.rb.
80
-
81
- h3. -r, --require FILE
82
-
83
- Causes FILE to be loaded (via require) before any specs are executed. If you're using a custom
84
- formatter, you have to specify this option *before* the --format option.
85
-
86
- h3. -d, --dry-run
87
-
88
- This option tells RSpec not to execute the specs, but they are still being parsed.
89
- This can be useful when generating "testdox-like":http://agiledox.sourceforge.net/ documents
90
-
91
- h3. -b, --backtrace
92
-
93
- In order to make it easier to identify causes of failing specifications, RSpec will filter out
94
- the parts of the backtrace that come from RSpec itself by default. If you wish to see them,
95
- you can use -b or --backtrace:
96
-
97
- <pre>
98
- $ bin/spec failing_examples/team_spec.rb -b
99
-
100
- {execute: ../bin/spec ../failing_examples/team_spec.rb -b}
101
- </pre>
102
-
103
- h3. -s, --spec &lt;name of context and/or specification&gt;
104
-
105
- Enter the name of a context, spec, or both to run:
106
-
107
- all the specs in a context ...
108
-
109
- <pre>
110
- $ bin/spec examples --spec "A stack with one item" -f s
111
-
112
- {execute: ../bin/spec ../examples --spec "A stack with one item" -f s}
113
- </pre>
114
-
115
- ... any spec in any context with a given name ...
116
-
117
- <pre>
118
- $ bin/spec examples --spec "should return top when sent top" -f s
119
-
120
- {execute: ../bin/spec ../examples --spec "should return top when sent top" -f s}
121
- </pre>
122
-
123
- ... or a specific spec in a specific context:
124
-
125
- <pre>
126
- $ bin/spec examples --spec "A stack with one item should return top when sent top" -f s
127
-
128
- {execute: ../bin/spec ../examples --spec "A stack with one item should return top when sent top" -f s}
129
- </pre>