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

Shared state between tests #275

Closed
iliabylich opened this issue Jul 19, 2016 · 3 comments
Closed

Shared state between tests #275

iliabylich opened this issue Jul 19, 2016 · 3 comments

Comments

@iliabylich
Copy link
Contributor

There are some weird conflicts between tests that define methods explicitly.

  • All blocks passed to it are evaluated on the context of MSpec's @env
  • This spec defines a method b.
  • This spec relies on method b to be undefined.
  • When rescue_spec runs before return_spec everything is fine.
  • When return_spec runs before rescue_spec this test fails.

Should we replace all occurrences of explicitly defined methods to evaluate("def ...", &block)?

@iliabylich
Copy link
Contributor Author

Here's a simplified example:

describe "Description" do
  evaluate <<-ruby, "Test 1" do
      def m1
        123
      end
    ruby

    m1.should == 123
  end

  it "Test 2" do
    def m2
      456
    end

    m2.should == 456
  end

  it "Test 3" do
    lambda { self.m1 }.should raise_error(NoMethodError)
    lambda { self.m2 }.should_not raise_error(NoMethodError)
  end
end

It passes because

  • m1 is defined on the instance of SpecEvaluate
  • m2 is defined on the shared MSpec@env

@eregon
Copy link
Member

eregon commented Jul 19, 2016

The environment is different per-file, isn't it?
If I run mspec language/return_spec.rb language/rescue_spec.rb with MRI I do not see an error.
In fact, I can confirm they are different objects by adding p self before those lines:

ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
[\ |                   0%                     | 00:00:00]      0F      0E#<Object:0x00560dda563770>
[\ | ==================50%                    | 00:00:00]      0F      0E#<Object:0x00560dda641fe8>
[- | ==================100%================== | 00:00:00]      0F      0E

So, maybe an Opal bug?
Is Opal somehow using RSpec to run these, partially maybe? The semantics could differ.
Or maybe since everything is compiled ahead of time, MSpec's @env is assumed to be a fixed value?

@iliabylich
Copy link
Contributor Author

I was testing on a single file 😄

So, maybe an Opal bug?

Yes, you are right, Opal runs all specs in the context of single object, this static object. Thanks for pointing that env is different per file!

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

No branches or pull requests

2 participants