How do I run a separate test in rspec?

I have searched all over the net but cannot find a solution for this and the following example does not work:

# spec/my_spec.rb
describe myText do
  it "won't work" do
    raise "never reached"
  end

  it "will work", :focus => true do
    1.should = 1
  end
end

$ rspec --tag focus spec/my_spec.rb

      

any helpers?

+3


source to share


1 answer


In general, to do a single BOM, you can simply do

rspec path/to/your/spec.rb:123

      

where 123

is the line number where your spec starts.

However, your specific example can never work because you have two typos:

1.should = 1

      

it should be

1.should eq 1      # deprecated to use 'should'

      

because otherwise you are assigning "1" to "1.should" which makes no sense.



You also cannot write "describe myText" because myText is not defined anywhere. You probably meant describe 'myText'

.

Finally, the preferred approach for RSpec assertions is

expect(1).to eq 1  # preferred

      

To prove it, I did:

mkdir /tmp/example
gem_home .
gem install rspec

cat spec.rb
# spec.rb
describe "example" do
  it "won't work" do
    raise "never reached"
  end

  it "will work", :focus => true do
    expect(1).to eq 1
  end
end

      

and this goes by by only executing the "will work" specification:

rspec --tag focus spec.rb
Run options: include {:focus=>true}
.

Finished in 0.0005 seconds (files took 0.05979 seconds to load)
1 example, 0 failures

      

+2


source







All Articles