fixtures

How to use ruby-on-rails fixtures for setting up (external) data that does not belong to the rails app DB?

巧了我就是萌 提交于 2019-12-24 02:52:57
问题 Per my requirements, I have created models for querying external database (different from the one that the rails app uses) for some of the data. I am trying to write tests around these models and want to separate the "sample test data" from the actual tests. I thought I could put the data in a yml file and load it into a hash, but it did work out :( Added sample test data to a fixture file name 'external_database.yml' Put the below code in setup, in the test file ext_data = YAML.load_file

How to pass faker data result to a custom function

感情迁移 提交于 2019-12-24 02:25:17
问题 I'm using PhoneNumberBundle for validates phone number on my application. I'm using also NelmioAliceBundle together with AliceFixtureBundle. Having that as start point I'm writing a fixture for a entity that has a PhoneNumberBundle assert for validate the phone number. Here is a snippet of that file: /** * @AssertPhoneNumber(defaultRegion="VE") * @ORM\Column(name="phone", type="phone_number", length=11) */ protected $phone; I don't know how to use external libraries on the fixture itself so

jasmine-jquery fixtures not loading

蹲街弑〆低调 提交于 2019-12-23 18:19:29
问题 Problem is that jasmine-jquery in not loading my fixtures from spec/fixtures folder. Now when I look at jasmine-jquery source code default path for fixtures is spec/javascripts/fixtures . In a version that I have, there is no spec/javascripts/fixtures folder. It seems it is something for Ruby gem. I also tried to create that javascripts folder but still it can't load it. When I place my fixture fragment inside of SpecRunner.html body - it works. Here is my html fragment: <ul class="fr"> <li><

ManyToMany Test Fixtures (Yaml) in Play Framework 1.2.x

你。 提交于 2019-12-23 12:51:43
问题 I'm using Play! 1.2.4 + Morhpia / MongoDB. My models are Salons and Stylists which share a many to many relationship. I am however unable to define the test data correctly to represent this relationship. Here's what I have done Salon(salon1): name: salon1 city: singapore country: singapore Stylist(stylist1): firstName: stylist1 lastName: stylist1 title: Stylist 1 price: $100 salons: [salon1] With this data, the stylist contains the reference to the salon but not vice-versa. How to achieve two

Fixtures with Paperclip

巧了我就是萌 提交于 2019-12-23 08:57:19
问题 I'm using Paperclip to store documents, but I can't find how to create fixtures of them, I wrote this : <% doc = Document.create(:asset => File.open(Rails.root.join('spec', 'assets', 'image.png'))) %> <%= part_event_image %>: asset_file_name: <%= doc.asset_file_name %> asset_content_type: <%= doc.asset_content_type %> asset_file_size: <%= doc.asset_file_size %> asset_updated_at: <%= doc.asset_updated_at %> documentable: party (Event) %> <% end %> But one I ran it, the document exist in the

pytest-mock mocker in pytest fixture

点点圈 提交于 2019-12-23 08:48:01
问题 I'm trying to find out why I don't seem to be able to use a mocked return value in a fixture. With the following imports import pytest import uuid pytest-mock example that works: def test_mockers(mocker): mock_uuid = mocker.patch.object(uuid, 'uuid4', autospec=True) mock_uuid.return_value = uuid.UUID(hex='5ecd5827b6ef4067b5ac3ceac07dde9f') # this would return a different value if this wasn't the case assert uuid.uuid4().hex == '5ecd5827b6ef4067b5ac3ceac07dde9f' The above test passes. However

if condition in setUp() ignore test

為{幸葍}努か 提交于 2019-12-22 14:39:09
问题 in unittest python library, exists the functions setUp and tearDown for set variables and other things pre and post tests. how I can run or ignore a test with a condition in setUp ? 回答1: You can call if cond: self.skipTest('reason') in setUp() . 回答2: Instead of checking in setUp , use the skipIf decorator. @unittest.skipIf(not os.path.exists("somefile.txt"), "somefile.txt is missing") def test_thing_requiring_somefile(self): ... skipIf can also be used on the class, so you can skip all

Fixtures and Selenium and Rails (oh my?)

北慕城南 提交于 2019-12-22 04:33:30
问题 What data do you use with Selenium tests on Rails apps? Do you load from fixtures? Use an existing dev db? Use a separate (non-fixture) db? I'm considering my options here. I have a Rails app with a large Selenium test suite that runs on a modified version of Selenium Grid. Part of the process, right now, is loading a large set of fixtures, once, before the test suite runs. It's a LOT of data. Most of it is reporting info exported from our production db. When I set it up originally, I

How to create fixtures with foreign key alias in rails?

妖精的绣舞 提交于 2019-12-21 22:02:28
问题 I have two models, App and User , where an App has a creator who is a User . # app.rb class App < ActiveRecord::Base belongs_to :creator, class_name: 'User' end # user.rb class User < ActiveRecord::Base has_many :apps, foreign_key: "creator_id" end How do I create fixtures for this? I tried: # apps.yml myapp: name: MyApp creator: admin (User) # users.yml admin: name: admin But this doesn't work, since the relation is an aliased foreign key, not a polymorphic type. Omitting the (User) in the

Unit testing a polymorphic association with fixtures

两盒软妹~` 提交于 2019-12-21 10:18:41
问题 I'm getting this error message: ERROR["test_profile_display", UsersProfileTest, 2.569931] test_profile_display#UsersProfileTest (2.57s) NoMethodError: NoMethodError: undefined method `posts' for nil:NilClass app/controllers/users_controller.rb:14:in `show' test/integration/users_profile_test.rb:22:in `block in <class:UsersProfileTest>' app/controllers/users_controller.rb:14:in `show' test/integration/users_profile_test.rb:22:in `block in <class:UsersProfileTest>' It seems character in the