1

I have a test that I want to run only when I specifically indicate that I want to run it.

Say I have a test that does a whack load.. It's a test that takes a user through all the steps necessary to purchase something from when the user signs up to when they bid on something and then when they pay for it, and even when they later get a refund for the purchase.

Now typically a massive test is a really bad idea. Tests should be small and discrete. I'm all for that. And I have those tests in place. But I also think that one omni-test is a good idea. Especially for something as significant as payments.

I expect the test to be slow and all over the database... so I don't really want to run it all that often. (only when I specifically ask for it)

So I'm wondering if there is a way to have a test only run when I specifically ask for. If I type "rspec' in my terminal then this massive test won't run.

baash05
  • 4,394
  • 11
  • 59
  • 97
  • Wow duplicate.. found the answer.. http://stackoverflow.com/questions/5918606/disable-a-group-of-tests-in-rspec – baash05 Apr 07 '15 at 08:05

2 Answers2

1

Sounds like you are looking to isolate certain 'features' to be run. Cucumber and Capybara use rspec underneath the covers to just this. Using this structure will be skipped unless specifically called. From the rspec core, use the tag options.

Example from https://www.relishapp.com/rspec/rspec-core/v/2-4/docs/command-line/tag-option

    describe "group with tagged specs" do
      it "example I'm working now", :focus => true do; end
      it "special example", :type => 'special' do; end
      it "slow example", :skip => true do; end
      it "ordinary example", :speed => 'slow' do; end
      it "untagged example" do; end
    end

Then, to test:

    When I run "rspec . --tag mytag"

Features Specs

Furthermore, using cucumber allows for feature tags for view testing.

  • From what I see the tagging doesn't matter when I run rspec with no filters. That's what I want.. no extra parameters, I want to not run the test.. parameters, run the test.. – baash05 Apr 07 '15 at 07:02
1

You can use ENV variables to conditionally change your configuration. For example, I use the following in my spec_helper.rb for disabling feature tests by default:

config.filter_run_excluding :type => 'feature' unless ENV['FEATURE']

Then, if you want to run the full test suite from your console, simply:

FEATURE=true rspec

You should be able to tweak this to suit your needs. Just remember to set the environment variable on your CI server if you want the feature specs to be run there.

Drenmi
  • 8,492
  • 4
  • 42
  • 51