require 'optparse/subcommand'

describe OptionParser do
  def run(args)
    options.parse(args.split(/\s+/))
    hits
  end

  let(:hits) { [] }
  let(:options) do
    OptionParser.new do |opt|
      opt.on '-t' do
        hits << :t
      end

      opt.subcommand 'foo' do |foo|
        hits << :foo

        foo.on '-q' do
          hits << :foo_q
        end
      end

      opt.subcommand 'bar' do |bar|
        hits << :bar

        bar.on '-s' do
          hits << :bar_s
        end
      end
    end
  end

  specify { run("-t").should == [:t] }
  specify { run("foo").should == [:foo] }
  specify { run("foo -q").should == [:foo, :foo_q] }
  specify { run("foo bar").should == [:foo] }
  specify { run("-t foo").should == [:t, :foo] }

  specify { lambda { run("foo -t") }.should raise_error(OptionParser::InvalidOption )}

  specify { options.to_s.should match(/foo/) }
end

require 'optparse/subcommand'

describe OptionParser do
  def run(args)
    options.parse(args.split(/\s+/))
    hits
  end

  let(:hits) { [] }
  let(:options) do
    OptionParser.new do |opt|
      opt.on '-t' do
        hits << :t
      end

      opt.subcommand 'foo' do |foo|
        hits << :foo

        foo.on '-q' do
          hits << :foo_q
        end
      end

      opt.subcommand 'bar' do |bar|
        hits << :bar

        bar.on '-s' do
          hits << :bar_s
        end
      end
    end
  end

  specify { expect(run("-t")).to eq([:t]) }
  specify { expect(run("foo")).to eq([:foo]) }
  specify { expect(run("foo -q")).to eq([:foo, :foo_q]) }
  specify { expect(run("foo bar")).to eq([:foo]) }
  specify { expect(run("-t foo")).to eq([:t, :foo]) }

  specify { expect { run("foo -t") }.to raise_error(OptionParser::InvalidOption )}

  specify { expect(options.to_s).to match(/foo/) }
end

Convert specs to RSpec 2.99.2 syntax with Transpec
Convert specs to RSpec 2.99.2 syntax with Transpec

This conversion is done by Transpec 3.3.0 with the following command:
    transpec

* 6 conversions
    from: obj.should
      to: expect(obj).to

* 5 conversions
    from: == expected
      to: eq(expected)

* 1 conversion
    from: lambda { }.should
      to: expect { }.to

For more details: https://github.com/yujinakayama/transpec#supported-conversions
