Forum: Ruby RSpec: how to delete duplicated rspec example

0466e3e1c1472474082f9a1bf86b3915?d=identicon&s=25 Roro Co (roroco)
on 2014-07-26 07:24
for instance:

class C
  def m(*args, &blk)

  end
end
describe "a desc" do
  it "a it with same name" do
  C.new.m
  end


  # in line 523
  it "a it with same name" do # it_example2
    C.new.m
  end
end


# in another spec file
describe "a desc" do
  it "a it with same name" do # it_example3
    C.new.m
  end
end

how to delete duplicate it examples(in above sample code, they are
it_example2 and it_example3) with some auto tool, i have try code
climate, it just check file.match([^spec]) duplication.
0466e3e1c1472474082f9a1bf86b3915?d=identicon&s=25 Roro Co (roroco)
on 2014-07-27 11:29
I fix it with below code:

require 'term/ansicolor'
require 'rspec'

all_example_full_descs = []
RSpec.configure do |c|
  c.before do |example|
    all_example_full_descs << example.metadata[:full_description]
  end

  c.after(:all) do
    puts all_example_full_descs
  end
end

describe 'a desc' do
  10.times do
    it "a it #{Time.now}" do
      puts Term::ANSIColor.red(Time.now)
    end
  end
end
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.