-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved spec library #167
Comments
I just created this issue to let people know that I'm working on this. |
I agree. But how do you plan to implement this? I was thinking a macro for I like the way you do macro assert_eq(expected, actual)
unless {{expected}} == {{actual}}
raise "assertion `#{ {{expected.stringify}} } == #{ {{actual.stringify}} }` failed: #{ ({{expected}}).inspect } != #{ ({{actual}}).inspect }"
end
end
assert_eq 2 + 2, 5 It's super clean (the usage, not the macro :-P) and the error you get on assertion failure is this:
One step further would be to be able to do: assert 2 + 2 == 5 and have macros pattern match that (so you can consider On the other hand, RSpec is also nice. The lengths are almost the same: assert 2 + 2 == 5
(2+2).should eq(5) and the matchers are all defined in Crystal, not in macro land. So I have mixed feelings about this :-) What's the problem with polluting |
@asterite I'll probably need to make The problem with adding So I was thinking of something like Hamcrest matchers, but a bit more flexible using the builder pattern. Something like this:
It's a bit more verbose, but reads better than even the new RSpec Yesterday I realized that with macros we could probably do something close to what you mentioned, showing the source as well as the results. This would work well with most kinds of matchers. I don't think we could get to the flexibility of allowing |
Hi @booch could you maybe make the list into a check list (e.g. Thanks! |
@PragTob That is because currently there is no scoping of Because of that To achieve that (+ additionally random order example execution), we will need to define examples inside of context without actually executing them, and we need to remember all calls to This can be achieved easily in the same way Other way, will be not that simple, but still not very complex: |
Just for reference: the describe/before/after/let macros to generate test classes/methods with inheritance are implemented in my minitest port. I didn't bench compile time and memory usage thought, but the more classes there are, the slower crystal compilation gets, so I'd expect it to get slower over time with many nested describes and let overrides. |
I'll close this. Alternatively, use minitest.cr if you need other funcionality, |
@asterite one of my main gripes with spec is also that all of the methods are implemented on a global level afaik. Are you open for improvements in that regard? |
@PragTob Did you find any conflicts so far? |
@asterite no, I just believe that no library should define methods on the main scope. I never know what a library will be used for, and maybe some application wants to define methods like |
@PragTob You mean something like this? The "problematic" methods are I believe (and you said "I just believe") this is more of a philosophical issue rather than a concrete one. For the time RSpec had them as globals, nobody complained and it worked fine. Then they had issues with BasicObject and blank slates and many things that just don't exist in Crystal, so they changed it. We also define |
@asterite no I'm not talking about should/should_not - not a big fan of those but I agree that it is nicer to type than the I'm talking about all the matchers ( Alltogether that are ~20 methods defined on the main object/global scope that no one using |
On ruby I am still running with bacon both for personnal and work projects and I mostly ignored the trend about rspec (which for me provides a lot of useless features for my needs), bacon let me write this: should 'add numbers' do
add(1, 4).should == 5
end compared to what crystal currently has: should 'add numbers' do
add(1,4).should eq(5)
end Only a |
I too was looking for |
@georgeu2000 well, @waterlink got you covered with spec2.cr. |
Our
Spec
class could use some improvements, to bring its feature set closer to something like RSpec:let
andlet!
before
blocks to help with setupsubject
eq
,be_true
, etc.) so they don't pollute global method namespaceexpect
syntax, or Hamcrest matchers'assertThat
syntax, so we don't have to polluteObject
's namespaceThese will likely require a major overhaul to the
Spec
class. It might make sense to replace the class instead.The text was updated successfully, but these errors were encountered: