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

Add support for Minitest::SharedExamples #46

Merged
merged 10 commits into from
Sep 4, 2016
Merged

Add support for Minitest::SharedExamples #46

merged 10 commits into from
Sep 4, 2016

Conversation

dingn1
Copy link
Contributor

@dingn1 dingn1 commented Sep 3, 2016

This is adding support for Minitest::SharedExamples. In Minitest we can use SharedExamples to create extensions inside application, which would make the searching of the test_method_name and test_path bad. This is adding a new pattern of searching when the old one does not work.

@dingn1 dingn1 changed the title Add support got Minitest::SharedExamples Add support for Minitest::SharedExamples Sep 3, 2016
@ArturT
Copy link
Member

ArturT commented Sep 3, 2016

Could you add shared example test in test_examples/fast/ directory.

In order to use shared example do we have to add another gem as dependency or it's just build in minitest gem?

Could you also update test in spec/knapsack/adapters/minitest_adapter_spec.rb to cover both context for regular test and shared example.

@dingn1
Copy link
Contributor Author

dingn1 commented Sep 3, 2016

It's just build in minitest gem. I will try update the specs.

@dingn1
Copy link
Contributor Author

dingn1 commented Sep 3, 2016

@ArturT I'm not so sure about the spec part could you give some guide? I just finished the base line of it. It's like a fake_test that include the SharedExampleSpec and should correctly return the test_path for that. On our project it worked for minitest spec syntax but I'm not sure how to do it here.

include Minitest::Spec::DSL
end

SharedExampleSpec = Minitest::SharedExamples.new do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You defined shared example here. Could you add at the bottom a new describe and include there shared example so we can see if they can be executed and recorded by knapsack (Travis will do that https://github.com/ArturT/knapsack/blob/master/.travis.yml#L62 ).

Copy link
Contributor Author

@dingn1 dingn1 Sep 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked locally executed fine. So I removed the spec in minitest_adapter

@ArturT
Copy link
Member

ArturT commented Sep 3, 2016

You could keep single describe for .test_path method. Here is example.

  describe '.test_path' do
    subject { described_class.test_path(obj) }

    before do
      parent_of_test_dir = File.expand_path('../../../', File.dirname(__FILE__))
      parent_of_test_dir_regexp = Regexp.new("^#{parent_of_test_dir}")
      described_class.class_variable_set(:@@parent_of_test_dir, parent_of_test_dir_regexp)
    end

    context 'when regular tes' do
      class FakeUserTest
        def test_user_age; end

        # method provided by Minitest
        # it returns test method name
        def name
          :test_user_age
        end
      end

      let(:obj) { FakeUserTest.new }

      it { should eq './spec/knapsack/adapters/minitest_adapter_spec.rb' }
    end

    context 'when shared example test' do
      class FakeSharedExampleUserTest
        # TODO
      end

      let(:obj) { FakeSharedExampleUserTest.new }

      it { should eq './spec/knapsack/adapters/minitest_adapter_spec.rb' }
    end
  end

You need to prepare proper FakeSharedExampleUserTest for your case. You could use binding.pry to bind in .test_path method and see what's the structure of the obj in case of shared example (the shared example you added in test_examples directory).

You can run tests from that directory with
KNAPSACK_TEST_FILE_PATTERN="test_examples/{,/*/}/*_test.rb" bundle exec rake "knapsack:minitest[--verbose]"

@@ -0,0 +1,31 @@
require 'test_helper'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rename this file to shared_examples_test.rb

@ArturT
Copy link
Member

ArturT commented Sep 3, 2016

I noticed you removed your test for .test_path method. I can write test for that then.

@ArturT ArturT merged commit e70438d into KnapsackPro:master Sep 4, 2016
@ArturT
Copy link
Member

ArturT commented Sep 4, 2016

I added missing spec for minitest adapter https://github.com/ArturT/knapsack/blob/master/spec/knapsack/adapters/minitest_adapter_spec.rb#L129

I've just released knapsack v1.12.0. I also updated pro version gem https://github.com/KnapsackPro/knapsack_pro-ruby ( https://knapsackpro.com )

@dingn1 Thank you for the PR and great work :)

@dingn1
Copy link
Contributor Author

dingn1 commented Sep 5, 2016

@ArturT Thanks for your help.

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.

2 participants