我正在尝试测试无序字符串中是否有5次"3".
例如:
var re = /3{5}/;
re.test("333334"); //returns true as expected
re.test("334333"); //returns false since there is no chain of 5 3s
Run Code Online (Sandbox Code Playgroud)
什么正则表达式会使第二行返回true?如果正则表达式不是测试它的最佳方法,那是什么?
谢谢!
我正在尝试为我的用户模型创建一个工厂,但是当我运行rspec时,我得到了
Failure/Error: user = build(:user, email: "invalid@email.com")
NameError:
uninitialized constant User
Run Code Online (Sandbox Code Playgroud)
当我跳进rails控制台时,我可以做User.all
,它会返回我拥有的用户并且FactoryGirl.build(:user, email: "invalid@email.com")
工作正常,所以我不确定问题出在哪里.
我用rails-api创建了项目,使用rails 4.2 ruby 2.2
# spec/spec_helper.rb
# i have to set spec/factories as the location explicitly or it won't find the factories
require 'factory_girl_rails'
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
FactoryGirl.definition_file_paths = [File.expand_path('../factories', __FILE__)]
FactoryGirl.find_definitions
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.filter_run :focus
config.run_all_when_everything_filtered = true
if config.files_to_run.one?
config.default_formatter = 'doc'
end
config.profile_examples = 10
config.order = …
Run Code Online (Sandbox Code Playgroud)