shoulda

Rspec / shoulda: testing, that a custom validator is called

有些话、适合烂在心里 提交于 2019-12-02 02:15:26
I have a custom validator (located in app/validators/uri_validator.rb) which is used in: validates :link, uri: true How do I specify this in my specs? Ideally I would like to have a one-line call, such as: it { should validate_uri_of(:link) } How do I do this? Another option is to use the allow_value matcher, although not ideal it can work in some circumstances. it { should allow_value(value_which_is_valid).for(:link) } it { should_not allow_value(value_which_is_invalid).for(:link) } Use factory girl to build a model object with invalid data and one with valid data and call the be_valid

Do shoulda-matchers' ActiveRecord matchers violate the “test behavior not implementation” rule?

折月煮酒 提交于 2019-12-01 18:57:28
For example, if I am using should validate_presence_of in my spec, that's only testing that I have the validate_presence_of piece of code inside my model, and that's testing implementation. More importantly, isn't that spec totally useless for testing the real problem, which is "if I don't fill out a certain field, will the model be saved successfully?" Some of shoulda-matchers' matchers don't test implementation, they test behavior. For example, look at the source for allow_value (which validate_presence_of uses): #matches? actually sets the instance's attribute to the value and checks to see

rspec and shoulda - complementary or alternatives?

纵然是瞬间 提交于 2019-11-30 07:19:05
I've used shoulda for a while, and I've read and played with rspec. I have not done an in depth compare and contrast. But it seems to me like there is some overlap between the two, but that they are not 1-1 replacements. I am considering writing some unit tests in my rails system with rspec, without replacing all the existing tests that are written with shoulda. Just as a way to get the feel. Is this a good idea? Can I gradually move from one to the other or am I asking for trouble? Any clear cut advantages of one over the other that I should consider? Thanks! Peter Brown I have to argue

rspec and shoulda - complementary or alternatives?

风格不统一 提交于 2019-11-29 09:18:28
问题 I've used shoulda for a while, and I've read and played with rspec. I have not done an in depth compare and contrast. But it seems to me like there is some overlap between the two, but that they are not 1-1 replacements. I am considering writing some unit tests in my rails system with rspec, without replacing all the existing tests that are written with shoulda. Just as a way to get the feel. Is this a good idea? Can I gradually move from one to the other or am I asking for trouble? Any clear

How to run Rails console in the test environment and load test_helper.rb?

一曲冷凌霜 提交于 2019-11-28 16:26:37
The background: I'm having some problems with Thoughtbot's "Factory Girl" gem, with is used to create objects to use in unit and other tests. I'd like to go to the console and run different Factory Girl calls to check out what's happening. For example, I'd like to go in there are do... >> Factory(:user).inspect I know that you can run the console in different environments... $ script/console RAILS_ENV=test But when I do that, Factory class is not available. It looks as though test_helper.rb is not getting loaded. I tried various require calls including one with the absolute path to test_helper

How to run Rails console in the test environment and load test_helper.rb?

前提是你 提交于 2019-11-27 09:43:29
问题 The background: I'm having some problems with Thoughtbot's "Factory Girl" gem, with is used to create objects to use in unit and other tests. I'd like to go to the console and run different Factory Girl calls to check out what's happening. For example, I'd like to go in there are do... >> Factory(:user).inspect I know that you can run the console in different environments... $ script/console RAILS_ENV=test But when I do that, Factory class is not available. It looks as though test_helper.rb