4

I've searched throughout the net but can't seem to find a solution to this and the following example is not working:

# 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 help guys?

Yaw Ansong Snr
  • 517
  • 5
  • 16
Simon
  • 113
  • 1
  • 8

1 Answers1

5

In general, to execute a single spec, you can just do

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

where 123 is the number of the line that your spec starts at.

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

1.should = 1

should be

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

because otherwise you're assigning "1" to "1.should", which doesn't make sense.

You also can't 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 this works, 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 passes, executing only the "will work" spec:

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
John Feminella
  • 303,634
  • 46
  • 339
  • 357