这是我在把一个项目里的常规test换成rspec测试时(就是TDD到BDD的转换)总结的一些正则表达式,说不定以后写个test_to_rspec的plugin里能用到.
[size=large]寻找"def test_should_find_some_one" “(def test\_)(\w+)”
替换为 "it 'should_find_some_one' do" “it '$2' do”
寻找"it 'should_be_more'" “(it +)(["|'])([a-z ]+)\_”
替换为 "it 'should be more'" “$1$2$3 ”
寻找"assert_equal a.value, b.value" “assert_equal[ |\(]([\w. :_\(\)]+),”
替换为 "a.value.should == b.value" “$1.should == ”
寻找"assert !Topic.exists?(id)" “assert !([\w. \S]+)\.(\w+)\?”
替换为 "Topic.should_not be_exists(id)" “$1.should_not be_$2”
寻找"assert Topic.exists?(id)" “assert[ +]([^!][\w. \S]+)\.(\w+)\?”
替换为 "Topic.should be_exists(id)" “$1.should be_$2”
[/size]
[size=large]寻找"def test_should_find_some_one" “(def test\_)(\w+)”
替换为 "it 'should_find_some_one' do" “it '$2' do”
寻找"it 'should_be_more'" “(it +)(["|'])([a-z ]+)\_”
替换为 "it 'should be more'" “$1$2$3 ”
寻找"assert_equal a.value, b.value" “assert_equal[ |\(]([\w. :_\(\)]+),”
替换为 "a.value.should == b.value" “$1.should == ”
寻找"assert !Topic.exists?(id)" “assert !([\w. \S]+)\.(\w+)\?”
替换为 "Topic.should_not be_exists(id)" “$1.should_not be_$2”
寻找"assert Topic.exists?(id)" “assert[ +]([^!][\w. \S]+)\.(\w+)\?”
替换为 "Topic.should be_exists(id)" “$1.should be_$2”
[/size]