Commit graph

1483 commits

Author SHA1 Message Date
Michael Miller
30a45a24d3 Restructure to use a composite design pattern
Examples and example groups now have a common ancestor.
2018-10-14 17:10:12 -06:00
Michael Miller
2070d7816b Root example group specialization 2018-10-14 14:28:05 -06:00
Michael Miller
3facf3af9d Change "description" to "what" for consistency 2018-10-14 11:50:08 -06:00
Michael Miller
68412daec0 Remove unused code 2018-10-14 01:02:52 -06:00
Michael Miller
77f631205e Break apart runnable example and document it 2018-10-11 10:16:48 -06:00
Michael Miller
34dce28663 Initial documentation and rework on runnable example 2018-10-10 16:57:43 -06:00
Michael Miller
81dce3df9a Cleanup and document some example classes 2018-10-10 13:05:17 -06:00
Michael Miller
53831ab36a Fix hook flags being nullable 2018-10-10 13:03:47 -06:00
Michael Miller
3e78f48d39 Pending examples weren't marked as finished 2018-10-09 14:53:51 -06:00
Michael Miller
d8223297af Treat harness more like a facade 2018-10-09 14:41:22 -06:00
Michael Miller
f5317ecbd3 Rig up the harness 2018-10-09 14:25:52 -06:00
Michael Miller
bfb133f44d Create example harness 2018-10-09 14:25:39 -06:00
Michael Miller
7b8f47f327 Implement expectation results 2018-10-08 11:25:22 -06:00
Michael Miller
c27f72c83e Add enum for example status 2018-10-07 16:13:17 -06:00
Michael Miller
64a233a9e1 Rename ExpectationRegistry to ExpectationReporter
Some initial implementation for the class.
2018-10-07 13:46:51 -06:00
Michael Miller
e14babc014 ExpectationFailed exception takes a result 2018-10-07 13:45:36 -06:00
Michael Miller
73a0d51c1b Rename message methods and add #failure? 2018-10-07 13:05:32 -06:00
Michael Miller
7277b3caaf Display actual value if label is empty 2018-10-07 12:49:10 -06:00
Michael Miller
38da6615bf Documentation for expectations and matchers 2018-10-07 12:42:09 -06:00
Michael Miller
d98bc05b88 Switch to structs to reduce memory allocations 2018-10-06 10:09:39 -06:00
Michael Miller
f11031f113 Upcast to fix type error 2018-10-06 09:58:58 -06:00
Michael Miller
79886e9efb More structure around exceptions and matching 2018-10-05 16:30:19 -06:00
Michael Miller
4c2f6157af Define some Expectation methods 2018-10-01 20:34:26 -06:00
Michael Miller
3035273e9a Rework how expectations and matchers work together 2018-09-28 11:47:42 -06:00
Michael Miller
4948fe0c6f Short-hand syntax for blocks with yield 2018-09-27 18:49:01 -06:00
Michael Miller
d670d96045 Remove extra assignment operations 2018-09-27 18:47:54 -06:00
Michael Miller
7484b92db9 Formatting 2018-09-27 17:50:50 -06:00
Michael Miller
b9abdb86ff Use actual value if label is empty
This will show a value instead of nothing if the should-syntax is used.
2018-09-27 16:28:47 -06:00
Michael Miller
77b4c71c2a Reduce nesting by collapsing modules with :: 2018-09-27 16:20:55 -06:00
Michael Miller
0d282d3d50 Wording - should-syntax instead of #should 2018-09-27 16:15:31 -06:00
Michael Miller
e9b8992130 Implemented should-syntax 2018-09-27 16:11:45 -06:00
Michael Miller
83a2a8e238 Manually include all sub-modules and top-level types
This is needed so that `spectator/should` is not included by default.
2018-09-27 15:49:34 -06:00
Michael Miller
1c9decaa41 Add documentation for top-level module 2018-09-27 15:41:18 -06:00
Michael Miller
1a61235cdc Simplify #examples and #groups methods 2018-09-27 13:51:19 -06:00
Michael Miller
f63f8b15a0 Use label (expression string) instead of value 2018-09-24 22:58:35 -06:00
Michael Miller
371fe680c2 Pass matcher messages to failure results 2018-09-24 22:57:37 -06:00
Michael Miller
8fb051d61e Add custom messages for matchers
This gives users natural, easier to understand text for expectations.
2018-09-24 22:56:48 -06:00
Michael Miller
562b544223 Capture expression string from expectations
This allows a string that the user had in source code instead of a resolved value.

This change requires storing a 'label' and changing expectation and matcher constructor methods to macros.
2018-09-24 22:51:26 -06:00
Michael Miller
ef7e0462cb GivenExampleGroupBuilder produces group of groups
Now a group is created for each element in the collection.
A group to contain the sub-groups is returned.
2018-09-24 00:25:15 -06:00
Michael Miller
1c7c6e5e90 Initial code for example names 2018-09-23 20:24:28 -06:00
Michael Miller
5e4f0f3bbc Initial formatting output for failures 2018-09-23 18:00:01 -06:00
Michael Miller
dcbca302dc Fix values being wrapped twice
This simplifies some code.
2018-09-23 17:13:30 -06:00
Michael Miller
cf0c438a5d Abstract away locals to SampleValues 2018-09-23 17:04:06 -06:00
Michael Miller
cddfe5591d Move ValueWrapper and TypedValueWrapper to Internals
Trying to hide from top-level some inner-workings.
2018-09-23 16:23:26 -06:00
Michael Miller
887a04a92a Remove unused classes 2018-09-23 16:13:48 -06:00
Michael Miller
7a6045a1f3 Change #it_behaves_like to a macro 2018-09-23 16:10:07 -06:00
Michael Miller
b3b8efdd59 Mark helper macros private 2018-09-23 16:07:58 -06:00
Michael Miller
70e37eeccf DRY up DSL 2018-09-23 16:07:03 -06:00
Michael Miller
0f323666a0 Fix methods for adding hooks 2018-09-23 15:41:58 -06:00
Michael Miller
855a5f2239 Move hook storage to their own class 2018-09-23 15:26:19 -06:00
Michael Miller
57c9f2c58e Copy/paste to reimplement pending examples 2018-09-23 14:53:32 -06:00
Michael Miller
56ae92a25d Add symbol for getting local from #given 2018-09-23 14:45:36 -06:00
Michael Miller
3c31783fd7 Pass arguments directly onto initializer with splat 2018-09-23 14:45:14 -06:00
Michael Miller
03a8efd7f8 Create test instance when example is created
This exposes errors in the framework
instead of delaying them until the test runs.
2018-09-23 14:39:05 -06:00
Michael Miller
94e2f54713 Implement building groups and examples 2018-09-23 14:34:42 -06:00
Michael Miller
5b79e76b44 Use builder to get example group 2018-09-23 13:40:24 -06:00
Michael Miller
037fe604ea Example group builder classes should build groups
It's implied in their name.
2018-09-23 13:40:16 -06:00
Michael Miller
d551cf6e1b Add missing GivenExampleGroupBuilder class 2018-09-23 12:27:21 -06:00
Michael Miller
6bf07e3967 Collection for #given is now an array of ValueWrapper 2018-09-23 12:27:08 -06:00
Michael Miller
faf3bef05c Fix typo 2018-09-23 12:21:10 -06:00
Michael Miller
fc1c0351cd Must use class variables 2018-09-23 12:19:29 -06:00
Michael Miller
ab7087649d Example wrappers need a top-level initializer
The default initializer made by the compiler takes no arguments.
Use this one to not create a default initializer.
2018-09-23 12:19:07 -06:00
Michael Miller
ecba0d00ec Pass group to example initializer 2018-09-23 12:16:38 -06:00
Michael Miller
09184f4a2a Group builder needs "what" as first arg 2018-09-23 12:15:53 -06:00
Michael Miller
0999cb2dbc Use fully-qualified names 2018-09-23 12:05:19 -06:00
Michael Miller
9109fc30fd Can pass types around (somewhat) at runtime
No need for extra factory classes.
2018-09-23 12:03:52 -06:00
Michael Miller
87d9cc438f Move code for root back to Spectator#describe
There seems to be a problem using def in block.
This broke helper methods and gives the error: `can't declare def 
dynamically`.
2018-09-23 12:02:51 -06:00
Michael Miller
9ba3fc898b More refatoring 2018-09-22 19:41:56 -06:00
Michael Miller
a1b5533504 Some initial work to cleanup the DSL builder 2018-09-22 15:15:29 -06:00
Michael Miller
a82076e2b7 Remove type from group macros
This value is never directly seen,
so it isn't necessary to support it.
2018-09-22 11:38:00 -06:00
Michael Miller
110a2b2d2a Quick exception handler for framework
This should be improved later.
2018-09-21 15:23:01 -06:00
Michael Miller
66ca06337d Fix locals not being passed to child groups 2018-09-21 14:26:09 -06:00
Michael Miller
a9d4acda36 Pass locals to example and test wrapper initializer
The #initialize method is defined in each context/given/module
that needs to add a local.
This is an elegant (although possibly confusing) solution.
2018-09-21 14:03:09 -06:00
Michael Miller
cba0abc7f1 Fixes for enumerating examples 2018-09-20 18:41:36 -06:00
Michael Miller
39be62c511 Temp disable until I figure out how to reference wrapped example 2018-09-20 18:41:21 -06:00
Michael Miller
007572f0b8 Get rid of #add_examples
Added #example_count method to help with array sizing.
2018-09-19 23:13:43 -06:00
Michael Miller
8b8981494d Trying to get exaples to map to their given values 2018-09-19 23:00:17 -06:00
Michael Miller
aaf973b8cf Concat #all_examples instead of recursive #add_examples 2018-09-19 22:28:20 -06:00
Michael Miller
4d601281f6 Delay example creation by using factories
The #given block functionality specifically needs this to create 
multiple examples.
2018-09-19 21:58:32 -06:00
Michael Miller
bb7f036a82 Make Example#group abstract
Instead of passing parent group as an argument, define the group method 
in the exapmle class created by the #it macro.
2018-09-19 21:50:51 -06:00
Michael Miller
0f7640411f Use symbols instead of strings for hash lookups 2018-09-19 21:06:10 -06:00
Michael Miller
a28f512ae4 Some code for repeating examples in given blocks 2018-09-19 20:49:01 -06:00
Michael Miller
830aa7b43a Structural code for enumerating given value sets 2018-09-19 20:00:26 -06:00
Michael Miller
2be9d65997 Add examples to group children 2018-09-19 19:32:59 -06:00
Michael Miller
06630e87d3 Rework how children are handled
Uses a loose version of the composite pattern.
This is to keep examples in the order they were declared.
2018-09-19 19:31:50 -06:00
Michael Miller
d679c356fd Move conditional into context macro 2018-09-19 19:29:33 -06:00
Michael Miller
fe81341e1a Rename MAPPING to GROUPS - better name 2018-09-19 18:58:44 -06:00
Michael Miller
41c0d9abc7 Initial changes for DSL refactor
No examples are picked up right now.
2018-09-19 18:53:09 -06:00
Michael Miller
fa73bf3a60 Hide method to infer type of first in collection in given macro
This was a bit of a hack.
2018-09-15 23:38:07 -06:00
Michael Miller
80fbe89b4c Track children in DSL 2018-09-15 16:58:59 -06:00
Michael Miller
a06ea6088c Shorten GroupDefinitions to Definitions 2018-09-15 16:53:28 -06:00
Michael Miller
196187a98a Add human-friendly formatting to runtime 2018-09-15 15:45:17 -06:00
Michael Miller
d1527d8c0d Change char for pending to * 2018-09-15 14:16:10 -06:00
Michael Miller
fd547c5814 Use Time::Span.zero instead of constructor with 0 nanoseconds 2018-09-15 14:10:59 -06:00
Michael Miller
caeab6c338 Cleanup color code 2018-09-15 14:04:17 -06:00
Michael Miller
625262b6d5 Colorize result string based on outcome 2018-09-15 13:51:28 -06:00
Michael Miller
8e1a2e114b Display summary from default formatter 2018-09-15 13:51:07 -06:00
Michael Miller
b329afffb6 Rename Report to TestResults 2018-09-15 13:31:55 -06:00
Michael Miller
ac53394b8d Additional methods to describe result 2018-09-15 13:30:07 -06:00
Michael Miller
5819e0201e Shorten names of result classes 2018-09-15 13:25:11 -06:00
Michael Miller
6ca4d8d2a6 Move matchers DSL into their own module
Moves the #eq method out of the global namespace.
2018-09-15 11:58:43 -06:00
Michael Miller
1ea06998e7 Move #expect from global namespace to example DSL 2018-09-15 11:30:45 -06:00
Michael Miller
967797428c Move DSL to its own directory 2018-09-15 11:21:23 -06:00
Michael Miller
b5cdda4af3 Shorten ExpectationFailedError to ExpectationFailed 2018-09-15 11:05:11 -06:00
Michael Miller
a1871ca62e Rename StandardFormatter to DefaultFormatter 2018-09-15 10:57:49 -06:00
Michael Miller
cfe1a014dd Rename reporters to formatters 2018-09-15 10:56:58 -06:00
Michael Miller
251bf5bb5e Remove unused source type 2018-09-15 10:53:00 -06:00
Michael Miller
a3366add13 Cleanup remaining references to "context" that should be "group" 2018-09-15 10:52:17 -06:00
Michael Miller
010b47ca1f Rename ContextDefinitions to GroupDefinitions 2018-09-15 10:49:46 -06:00
Michael Miller
7968c5a394 Rename Context to ExampleGroup 2018-09-15 10:45:47 -06:00
Michael Miller
dc8e651209 Quick implementation of pending examles 2018-09-15 10:36:20 -06:00
Michael Miller
56229cdc93 Move common example runner code into new RunnableExample class 2018-09-14 22:17:16 -06:00
Michael Miller
e4d46ca603 Initial implementation of invoking #around_each hooks
My brain hurts. 😖
2018-09-13 10:44:21 -06:00
Michael Miller
9f778c5cb9 Fix after_all hooks running too soon 2018-09-12 21:31:44 -06:00
Michael Miller
77753ab974 Move hook execution into Example#run 2018-09-12 20:42:39 -06:00
Michael Miller
5b275f3146 Use #unsafe_as
The value can't be any other type, so this should be a safe operation.
2018-09-12 20:28:36 -06:00
Michael Miller
fbea3533ea Remove setter and extra code for given vars 2018-09-12 20:27:11 -06:00
Michael Miller
e30da2be19 Some macro cleanup 2018-09-12 19:23:27 -06:00
Michael Miller
9b07f669ed Remove Locals sub-module
This allows for seamless helper methods.
2018-09-12 19:16:41 -06:00
Michael Miller
3fc625de3f Allow generic types for #described_class and implicit #subject
Add runtime check to ensure #described_class is a type name.
2018-09-12 18:54:46 -06:00
Michael Miller
037612d00a Add implicit subject 2018-09-12 18:37:33 -06:00
Michael Miller
8cf876268a Use fresh variables 2018-09-12 16:29:48 -06:00
Michael Miller
10fc6c6a35 Hide special character mapping 2018-09-12 15:54:45 -06:00
Michael Miller
625a331745 Initial code to indirectly run example
This issolates the example code from the example class' attributes, such
as #description, #run, and others.
2018-09-12 15:47:57 -06:00
Michael Miller
700108f52f Move example-specific DSL to its own module 2018-09-12 15:41:23 -06:00
Michael Miller
4bfd2b9620 Rearrange DSL 2018-09-12 15:21:23 -06:00
Michael Miller
e451c027a8 Fix bad copy/paste for hooks 2018-09-12 15:16:18 -06:00
Michael Miller
193314d532 Fix given variables being defined in parent context 2018-09-12 15:13:46 -06:00
Michael Miller
8b55d9139d Hide constants used to build test hiearchy 2018-09-12 14:53:11 -06:00
Michael Miller
c2ee9fd520 Move ROOT_CONTEXT out of Spectator module 2018-09-11 20:25:28 -06:00
Michael Miller
6f6ba9c812 Obscure given value setter 2018-09-11 16:19:31 -06:00
Michael Miller
65e8ee3788 Fix string descriptions having extra quotes 2018-09-11 16:01:31 -06:00
Michael Miller
84ed9c41b2 Store example description 2018-09-11 15:57:18 -06:00
Michael Miller
d8621fc43e Store "what" string in context 2018-09-11 15:54:00 -06:00
Michael Miller
284e10482a Add names for most common special characters
These names will be used instead of an underscore. This helps with
naming.
2018-09-11 15:09:23 -06:00
Michael Miller
95ec999bba Hide name of underlying let's block method
This prevent's defining a bang version of the let value with the same
name.
2018-09-11 12:54:47 -06:00
Michael Miller
2c0238d178 Invoke before_each, before_all, after_each, and after_all hooks 2018-09-10 22:33:40 -06:00
Michael Miller
a725c0d5be Pass context to examples 2018-09-10 21:51:14 -06:00
Michael Miller
2ff8ebb3cb Implement creation of hooks 2018-09-10 21:27:24 -06:00
Michael Miller
387e129a89 Add context instances 2018-09-10 19:59:57 -06:00
Michael Miller
65da494e52 Fix for no block arg in #given - "value" treated as StringLiteral 2018-09-10 19:28:57 -06:00
Michael Miller
b1d44fb480 Remove source tracking since it doesn't work right with macros 2018-09-07 21:49:46 -06:00
Michael Miller
aa1764d972 Cleanup contextual arguments 2018-09-07 18:20:54 -06:00
Michael Miller
27e3f00d70 Remove RunOrder
Examples will be sorted by using the decorator pattern.The collection of
examples will be wrapped when a custom run order isused.
2018-09-07 15:06:57 -06:00
Michael Miller
cb0ae516ae Catch duplicate given blocks with same variable name 2018-09-06 22:39:40 -06:00
Michael Miller
5646a6ebd9 Remove unecessary underscores 2018-09-06 22:23:57 -06:00
Michael Miller
45261c419f Super hacky way to resolve type of given variables 2018-09-06 22:08:32 -06:00
Michael Miller
7c8be54e5c Mostly complete code for #given 2018-09-06 21:13:03 -06:00
Michael Miller
3e7f43009f Use more correct name for constant 2018-09-06 19:22:47 -06:00
Michael Miller
f7eeb2b2a3 Implement #described_class 2018-09-04 16:59:59 -06:00
Michael Miller
7ff91b4fc6 Rename "context" to "locals"
Remove possible confusion around variables (let and subject) and context
keyword.
2018-09-04 16:17:33 -06:00
Michael Miller
de55e31407 Add basics for tracking source code location 2018-09-04 13:36:19 -06:00
Michael Miller
b8dcf35165 Add report for suite results 2018-08-30 23:38:20 -06:00
Michael Miller
9d39bc80b1 Fix filename 2018-08-30 23:24:49 -06:00
Michael Miller
792bca99e5 Simplify rescue 2018-08-30 22:50:27 -06:00
Michael Miller
fb4dd9fd22 Fix default run order 2018-08-30 22:47:40 -06:00
Michael Miller
f4de0ffee9 Capture elapsed test time 2018-08-30 22:45:49 -06:00
Michael Miller
e38fddb12a Initial code for reporters 2018-08-30 22:21:10 -06:00
Michael Miller
aba9f50d58 Remove unused results 2018-08-30 21:57:44 -06:00
Michael Miller
9fb1a3b664 Add base classes for defining example run order 2018-08-30 21:32:13 -06:00
Michael Miller
c100651680 Handle errored and failing specs separately
An errored example is one that throws an exception that is not from an 
expectation failing.
2018-08-30 21:15:20 -06:00
Michael Miller
65b16f9031 Capture exception from failed specs 2018-08-30 21:10:36 -06:00
Michael Miller
3aa6ab7a10 Some initial work on spec runner 2018-08-30 21:07:14 -06:00
Michael Miller
cf789f54be Remove code for running examples
Preparing to add runner.
2018-08-30 15:55:20 -06:00
Michael Miller
a65aedbfb7 Implement #to_not 2018-08-30 14:15:07 -06:00
Michael Miller
5eb5561e61 Rename Proxy to Wrapper 2018-08-30 14:07:46 -06:00
Michael Miller
a0fbc61244 Extraneous debug code 2018-08-30 14:03:29 -06:00
Michael Miller
e26fecd092 Fix let/subject not being passed to nested contexts 2018-08-30 14:02:18 -06:00
Michael Miller
24725c4f9d Top-level describe (Spectator.describe) missing module namespace 2018-08-30 13:29:11 -06:00
Michael Miller
aeb09b4e0d The #is_expected macro must be in example for visibility in #it 2018-08-28 16:44:21 -06:00
Michael Miller
b1d70453cf Implement #let! 2018-08-28 16:37:28 -06:00
Michael Miller
709b226f8e Implement #let functionality 2018-08-28 16:33:23 -06:00
Michael Miller
623033623a Add untyped ValueProxy base class 2018-08-25 18:36:32 -06:00
Michael Miller
0af4c2f54f Add lazy class 2018-08-25 18:25:21 -06:00
Michael Miller
d5cd756882 Remove private nest macro
It was still visible to end users.
2018-08-24 15:17:05 -06:00
Michael Miller
b90cc39638 Playing around with contexts and examples 2018-08-24 14:53:14 -06:00
Michael Miller
ed40e995d2 Playing around with new macro style 2018-08-23 16:24:03 -06:00
Michael Miller
74905b82bd Minimal handling of expectations and failures 2018-08-23 12:44:40 -06:00
Michael Miller
7ec33943a4 Initial structure for matchers 2018-08-23 12:44:18 -06:00
Michael Miller
b709820e11 Add expectation class 2018-08-21 21:07:37 -06:00
Michael Miller
0ade9f4dfd Some cleanup 2018-08-19 01:38:02 -06:00
Michael Miller
0613344230 Scratch work on structure 2018-08-19 01:15:32 -06:00
Michael Miller
630e537726 Initial commit 2018-08-18 15:33:20 -06:00