Commit graph

1030 commits

Author SHA1 Message Date
Davide Paolo Tua
ce9bf918c1 Fix syntax errors in be_between matcher 2020-02-21 12:48:22 +01:00
Michael Miller
3aaab0e74f Fix memoized subject from context description another way
The other method gave a strange compiler error when running specs.
Something to do with "K" not having an inspect method.

In /usr/share/crystal/src/hash.cr:1826:13

 1826 | key.inspect(io)
            ^------
Error: undefined method 'inspect' for K
2020-02-16 19:50:20 -07:00
Michael Miller
5cb74ebe95 Bump version to 0.9.7 2020-02-16 19:36:09 -07:00
Michael Miller
dd48bf6f25 Fix subject not being memoized when using described_class 2020-02-16 19:34:48 -07:00
Michael Miller
2aba67edae Fix idiosyncrasies around class method stubs
The new method misbehaves here.
It always appeared as defined, even though it isn't explicitly defined 
in the class.
2020-02-14 18:14:32 -07:00
Michael Miller
7a8e570bea Fix typo with should_eventually 2020-02-10 17:50:35 -07:00
Michael Miller
63ff59688b Bump version to 0.9.6 2020-02-10 17:47:02 -07:00
Michael Miller
a7db9ff0bb Don't force previous_def on class methods 2020-02-10 17:46:36 -07:00
Michael Miller
d30e65ee2d Missing ? on method name check 2020-01-20 20:42:16 -07:00
Michael Miller
721425c3c8 Run deferred expectations after all hooks 2020-01-20 20:15:49 -07:00
Michael Miller
60f1c3091b Allow be matcher to be used on structs 2020-01-19 22:39:21 -07:00
Michael Miller
b1984b343a Add should keywords to examples
Allows short-hand like:
it { should be_empty }
2020-01-19 22:12:06 -07:00
Michael Miller
e60c287216 Fix a dumb with merge 2020-01-19 10:05:21 -07:00
Michael Miller
1825026af7 Bump version to 0.9.4 2020-01-19 09:53:20 -07:00
Michael Miller
64f6456935 Merge branch 'specs' 2020-01-19 09:52:41 -07:00
Michael Miller
272ebcd693 Fix subject with group describing a type
An explicit subject should be used when describing a type. This mimics 
RSpec.
2020-01-19 09:52:12 -07:00
Michael Miller
a2508d5f6b Fix negation case for respond_to matcher 2020-01-17 22:08:52 -07:00
Michael Miller
e8a437dc0a Bump version to 0.9.3 2020-01-17 14:53:04 +03:00
Michael Miller
f825a34771 Fix issue with implicit vs. explicit subject
Addresses the issue pointed out in !25

There was a recent change that set a subject to the first argument of 
`describe` and `context`. This prevented an explicitly defined subject 
from being accessible in nested groups.
2020-01-17 14:53:03 +03:00
Michael Miller
2b2fb5af3a Bump version to 0.9.3 2020-01-16 18:37:04 -07:00
Michael Miller
13a0b9e2d3 Fix issue with implicit vs. explicit subject
Addresses the issue pointed out in !25

There was a recent change that set a subject to the first argument of 
`describe` and `context`. This prevented an explicitly defined subject 
from being accessible in nested groups.
2020-01-16 18:36:40 -07:00
Michael Miller
b25388a165 Merge branch 'specs' of gitlab.com:arctic-fox/spectator into specs 2020-01-14 20:10:53 -07:00
Michael Miller
d807f9866a Bump version to 0.9.2 2020-01-14 20:09:15 -07:00
Michael Miller
c48b9ed9e1 Resolve let! not working on uninferable types
Resolves https://github.com/icy-arctic-fox/spectator/issues/4
Use ValueWrapper trick again and initialize immediately with before_each 
hook.
2020-01-14 20:07:56 -07:00
Michael Miller
d5c5a82395 Add with_message modifier to raise_error matcher 2020-01-06 23:46:38 -07:00
Michael Miller
f11b548f4e Mimic RSpec behavior of match matcher
The code:
expect(/foo/).to match("food")
would normally evaluate:
"food" === /foo/
which is false.
However, in RSpec, this expectation is true.
2020-01-06 23:01:45 -07:00
Michael Miller
5fa6b5d549 Fix negation expectation text 2020-01-06 22:11:36 -07:00
Michael Miller
590d81979e Workaround typing issues 2020-01-06 22:04:05 -07:00
Michael Miller
5673144527 Fix negative match case for contain/cover matcher 2020-01-05 23:01:25 -07:00
Michael Miller
b7c686e836 Add cover matcher
Works the same as `contain` but is for ranges.
2020-01-05 22:49:27 -07:00
Michael Miller
8143229fdb Fix failure message 2020-01-05 22:47:57 -07:00
Michael Miller
034c1cd6cb Change array matcher to allow any order 2020-01-05 11:42:39 -07:00
Michael Miller
93c442d1e2 Add instance_of matcher to check exact type 2020-01-04 12:46:08 -07:00
Michael Miller
8cfed440ed Fix typo with be_a matcher 2020-01-04 12:45:49 -07:00
Michael Miller
c3688807d4 Add kind_of aliases for be_a matcher 2020-01-04 10:08:01 -07:00
Michael Miller
34060ce181 Ensure top-level Crystal types are used 2020-01-04 09:49:28 -07:00
Michael Miller
c4a97230f1 Remove unecessary members provided by ValueMatcher 2020-01-04 09:33:14 -07:00
Michael Miller
4c9d767137 Add missing description arguments 2020-01-04 09:32:56 -07:00
Michael Miller
71740113d5 Allow subject for non-class types 2020-01-02 19:30:46 -07:00
Michael Miller
88ed415191 Bubble up matcher description
The last run matcher's description is used if one wasn't provided by the 
user.
Only applies to examples that actually run and have expectations.
2020-01-02 19:19:55 -07:00
Michael Miller
d64ecc4192 Store matcher description in MatchData 2020-01-02 19:16:33 -07:00
Michael Miller
00fe913d77 Add predicate method to check for description 2020-01-02 18:43:30 -07:00
Michael Miller
ff2cbcd4c7 Allow test description to be blank
Currently defaults to the example's source.
2020-01-02 18:40:25 -07:00
Michael Miller
061028782b Workaround for what seems to be a Crystal macro bug
The syntax:
stub instance.==(other) { true }
effectively becomes:
stub instance.==(other { true })
2020-01-01 21:48:58 -07:00
Michael Miller
612222ace8 Update version to 0.9.1 2019-12-13 20:26:22 -07:00
Michael Miller
8ccc08b472 Fix reflection (verify double) on self arg type
There is still an issue with using _ for a placeholder.
2019-12-13 20:25:18 -07:00
Michael Miller
16625cf495 Registry#expect takes a stub 2019-12-13 19:56:43 -07:00
Michael Miller
a38625f8a7 Remove GenericMethodCall
This type isn't needed. MethodCall is suitable after moving arguments to
it.
2019-12-13 19:54:06 -07:00
Michael Miller
a6aa00eb38 Fix double default stub with type 2019-12-13 19:17:08 -07:00
Michael Miller
4c9bbbe07b Formatting 2019-12-08 15:11:23 -07:00
Michael Miller
0ae5cdc9ae Remove debug 2019-12-08 15:11:08 -07:00
Michael Miller
1a30a56f2a Better stringified call 2019-12-08 15:10:49 -07:00
Michael Miller
91696d490f Check if underlying type responds to method 2019-12-08 15:08:13 -07:00
Michael Miller
067c789019 Initial work on type reflection for verifying doubles 2019-12-08 14:52:54 -07:00
Michael Miller
074aff531c Add "anything" which always returns true when compared against 2019-12-08 14:52:28 -07:00
Michael Miller
07ce835724 VerifyingDouble should be abstract 2019-12-08 14:51:48 -07:00
Michael Miller
8b0f509689 Detect when to use a verifying double 2019-12-08 11:37:08 -07:00
Michael Miller
8197a82ace Expect stubs not method names
Needed for argument syntax:
`expect(dbl).to receive(:foo).with(:bar)`
2019-11-29 09:25:58 -07:00
Michael Miller
c710961be1 Fix returned type inferred to NoReturn 2019-11-29 08:53:36 -07:00
Michael Miller
d6c1169bc3 Fix dumb syntax 2019-11-20 20:40:53 -07:00
Michael Miller
5d84536e1e Implement and_call_original 2019-11-20 19:17:51 -07:00
Michael Miller
f8563e86c7 Pass along original block 2019-11-20 16:29:06 -07:00
Michael Miller
2dee50f19e Pass original (and type constraint) to stub via block 2019-11-20 15:43:45 -07:00
Michael Miller
51a47fec98 Remove unused RT parameter 2019-11-20 15:05:04 -07:00
Michael Miller
27acf7bced Allow receive block syntax 2019-11-19 17:28:00 -07:00
Michael Miller
b062472d98 Revert "Initial support for and_yield"
This reverts commit e49bd0d57a.

Removing support for stubbed yield.
Attempting to yield with different a different arity or argument types causes compilation errors.
I don't see any easy fix for this.
I would rather have no yield support than broken support.
2019-11-17 13:30:09 -07:00
Michael Miller
e49bd0d57a Initial support for and_yield 2019-11-17 13:12:39 -07:00
Michael Miller
b896a7f1d5 Implement stub that raises 2019-11-17 12:53:18 -07:00
Michael Miller
6e287f864b Implement returning multiple values 2019-11-17 12:26:02 -07:00
Michael Miller
1a3f663b70 Name is optional for doubles 2019-11-17 10:47:51 -07:00
Michael Miller
a63d3d05a5 Negation for receive matchers 2019-11-17 10:32:37 -07:00
Michael Miller
5da231a5e8 Check expectations for anonymous double 2019-11-17 10:14:03 -07:00
Michael Miller
45fe6217b4 Missing args 2019-11-17 09:42:19 -07:00
Michael Miller
ac9b3ad1fe Implement expect_any_instance_of 2019-11-16 21:27:18 -07:00
Michael Miller
a15e2a97b1 Allow deferred expectation of multiple stubs 2019-11-16 15:24:23 -07:00
Michael Miller
a8e0f46645 Revert "Coerce operations in match? to booleans"
This reverts commit 76c21d447a.

Should no longer be needed since mocks and doubles should indirectly leak into StandardMatcher types.
2019-11-16 15:15:53 -07:00
Michael Miller
d9d30c57d0 Merge ReceiveArgumentsMatcher and ReceiveMatcher
Finally found the issue causing other matchers derived from
StandardMatcher to be "leaked" doubles and mocks indirectly.
The if-condition in ExpectationPartial#to and #to_not caused the matcher
to be given the StandardMatcher type instead of a union type.
This lead to really strange compilation errors and wasted a lot of
hours.
2019-11-16 15:14:38 -07:00
Michael Miller
f0bfd8b6d4 Switch to run-time error for unsupported negation 2019-11-16 13:18:09 -07:00
Michael Miller
201fe614d1 Expect messages on double, but don't stub them 2019-11-16 10:59:13 -07:00
Michael Miller
186fa15a1a Add method to check for stub 2019-11-16 10:06:11 -07:00
Michael Miller
8dbfb2d6ec Revert "Allow expected value to receive stub"
This reverts commit 6cd410c4c7.

Should not stub the method.
The end-user needs to do this.
2019-11-16 09:23:45 -07:00
Michael Miller
c9fb4d2d33 Don't run deferred blocks if the test fails
This also prevents overriding the test's original error with on that may 
occur in the deferred blocks.
2019-11-16 09:06:47 -07:00
Michael Miller
23d8f4b5a6 Formatting 2019-11-16 09:03:24 -07:00
Michael Miller
ca85acefaf Resolve issue trying to splat union of named tuples 2019-11-16 09:02:57 -07:00
Michael Miller
85531fecf9 Fix truthy values not being strings 2019-11-16 09:01:03 -07:00
Michael Miller
76c21d447a Coerce operations in match? to booleans
The compiler is merging null-doubles with these matchers.
Methods that normally return a boolean instead return the instance 
(self).
This causes a return type-mismatch.
There should be a better alternative to this.
2019-11-16 08:49:09 -07:00
Michael Miller
6cd410c4c7 Allow expected value to receive stub 2019-11-16 08:32:13 -07:00
Michael Miller
72e4ac8fe9 Remove unnecessary free variables 2019-11-16 08:17:46 -07:00
Michael Miller
3c94d1f8fd Workaround for generic argument type issue 2019-11-15 21:18:51 -07:00
Michael Miller
2dc86c05ac Initial work on deferred have_received check 2019-11-14 19:35:13 -07:00
Michael Miller
98bfed2f83 Expose name and source 2019-11-14 19:17:55 -07:00
Michael Miller
ac3a5c8515 Store GenericArguments 2019-11-14 19:15:51 -07:00
Michael Miller
763c99f338 Formatting 2019-11-14 18:48:43 -07:00
Michael Miller
28ec1062e8 Merge branch 'release/0.9' into dev/mocks-and-doubles 2019-11-14 18:47:25 -07:00
Michael Miller
6b3885af30 Run deferred blocks 2019-11-14 18:41:26 -07:00
Michael Miller
2128184659 Implement defer logic in harness 2019-11-14 18:30:48 -07:00
Michael Miller
173f7bfa13 Add should_eventually and should_never methods 2019-11-14 18:26:24 -07:00
Michael Miller
a80d018ff6 Remove type annotation/requirement 2019-11-14 18:23:45 -07:00
Michael Miller
bd0396c001 Add to_eventually and to_never operations
This defines what they should look like.
2019-11-14 18:19:37 -07:00
Michael Miller
b40abe8057 Fix GenericArguments#to_s 2019-11-14 18:06:20 -07:00