Skip to content
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

split spec files, to module and runner #3631

Closed
wants to merge 1 commit into from

Conversation

kostya
Copy link
Contributor

@kostya kostya commented Dec 3, 2016

i want to use spec dsl expectations in production code O_o, to check some metrics for nagios:
but i don,t want to run spec runner.

with this pr, i can do this:

require "spec/spec"

begin
  1.should eq 2
rescue ex : Spec::AssertionFailed
  p ex.message
end

"expected: 2\n got: 1"

@asterite
Copy link
Member

asterite commented Dec 6, 2016

Oh, I forgot to merge this before 0.20.1, sorry.

In any case, I think require "spec" and require "spec/spec" look very similar to it might be confusing. Maybe we can use require "spec/dsl"? (because you basically want the DSL)

To do that you might need to make a few more changes, but I think I would prefer that name (I know there is a spec/dsl file now, but we can freely move things around because everyone just does require "spec")

@RX14
Copy link
Contributor

RX14 commented Dec 6, 2016

What about require "assertions" because that's essentially what the should part of the dsl is.

@asterite
Copy link
Member

@kostya What is the real use case behind this?

I can imagine this:

if some_condition_doesnt_hold
  send_email_saying_assertion_failed
end

But I don't know if I'd do it with the spec dsl... for one, it's a bit slower because an exception is raised. But in general, I think an if is better here.

@kostya
Copy link
Contributor Author

kostya commented Dec 19, 2016

need to write many checks, for ~ 50 tasks, especially when you parse something from internet, it can include many conditions, need nice error messages from it.

class SomeTask
  # ...

  # check that task is ok executed
  check do |value|
    value["bla"].should eq "something"
    value["aaa"].should contain("some")
    value["bbb"].should eq 10
    value["ccc"].should eq [1, 2, 3]
    value["d"].as_i.should be > 0
    # ...
  end
end

if i write it with if and custom error messages, code become so bigger.
speed no matter here, because it checks periodically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants