Git Product home page Git Product logo

Comments (2)

mylesmegyesi avatar mylesmegyesi commented on September 28, 2024

This issue came up a while ago: GH-26. I think the root problem is about mismatched expectations.

Since Speclj is based on RSpec, I assumed that it components worked just like RSpec; when they are run they attach themselves to their current context. For example, this works in RSpec:

describe "it blocks" do

  def self.run_me
    it "runs this test" do
      1.should == 2
    end

    it "and it runs this test" do
      2.should == 1
    end
  end

  run_me
end
$ rspec it_spec.rb
FF

Failures:

  1) it blocks runs this test
     Failure/Error: 1.should == 2
       expected: 2
            got: 1 (using ==)
     # ./it_spec.rb:7:in `block in run_me'

  2) it blocks and it runs this test
     Failure/Error: 2.should == 1
       expected: 1
            got: 2 (using ==)
     # ./it_spec.rb:11:in `block in run_me'

Finished in 0.00088 seconds
2 examples, 2 failures

Failed examples:

rspec ./it_spec.rb:6 # it blocks runs this test
rspec ./it_spec.rb:10 # it blocks and it runs this test

However, Speclj differs. it components do not attach themselves to the current context. Instead, describe components will attach any components that are passed to it. So, in @skatenerd 's example, only the last example is passed to the describe block; resulting in a test that never runs.

from speclj.

slagyr avatar slagyr commented on September 28, 2024

Right. A Context (describe block) is a collection of Examples (it blocks). So when your test code is evaluated, Speclj collects a sequence of Contexts, which in turn collect a sequence of Examples; but none of the tests are “Executed” yet. This is good for a couple reasons.

  1. It fits the functional paradigm. Executing the tests generates side effects. Speclj postpones that as long as possible.
  2. The tests can be re-run. They’re just a bunch of functions stored in an persistent collection. Custom Runners can take advantage of this fact like the Vigilant (auto) runner does.

Knowing this, the use of ‘let’ should seem suspicious. Because the bindings are only valid when the specs are evaluated. You may not get what you want at execution time. Speclj provides components that you’ll prefer to use (‘with’ ‘before’ ‘after’ …)

That said, it is often useful to use a ‘for’ form to generate multiple examples. So long as your specs are wrapped in a list, which is what the ‘for’ form does, Speclj will flatten the nested structure.

On Jan 22, 2014, at 9:22 AM, Myles Megyesi [email protected] wrote:

This issue came up a while ago: GH-26. I think the root problem is about mismatched expectations.

Since Speclj is based on RSpec, I assumed that it components worked just like RSpec; when they are run they attach themselves to their current context. For example, this works in RSpec:

describe "it blocks" do

def self.run_me
it "runs this test" do
1.should == 2
end

it "and it runs this test" do
  2.should == 1
end

end

run_me
end
$ rspec it_spec.rb
FF

Failures:

  1. it blocks runs this test
    Failure/Error: 1.should == 2
    expected: 2
    got: 1 (using ==)

    ./it_spec.rb:7:in `block in run_me'

  2. it blocks and it runs this test
    Failure/Error: 2.should == 1
    expected: 1
    got: 2 (using ==)

    ./it_spec.rb:11:in `block in run_me'

Finished in 0.00088 seconds
2 examples, 2 failures

Failed examples:

rspec ./it_spec.rb:6 # it blocks runs this test
rspec ./it_spec.rb:10 # it blocks and it runs this test
However, Speclj differs. it components do not attach themselves to the current context. Instead, describe components will attach any components that are passed to it. So, in @skatenerd 's example, only the last example is passed to the describe block; resulting in a test that never runs.


Reply to this email directly or view it on GitHub.

from speclj.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.