dry

How to reuse beforeEach/afterEach in Jasmine JS?

橙三吉。 提交于 2019-11-27 07:33:53
When writing tests with JasmineJS I have many tests that have similar beforeEach/afterEach code. Is there a way to implement an inheritance model using JasmineJS test suites? I can group all tests in a single describe but in this case I will end with a single HUGE JS file containing all tests. I would like to split the tests for each page. Here is an example: describe('Services Page', function() { beforeEach(function() { login_as_admin() }) beforeEach(function() { browser().navigateTo('/services') }) if('Some test for services page', function() {}) afterEach(function() { logout() }) })

Concepts for RDFa DRY references

自古美人都是妖i 提交于 2019-11-27 07:31:29
问题 I started digging into RDFa recently and try to spice my website with semantic information. The site offers services, events, a blog and may offer products in future. Happily schema.org has coarse but adequate categories for it all. But now it comes to practical questions. All the examples have all information on a single page, which seems pretty academic to me. E.g. on my landing page is a list with upcoming events. Events have a location property. My events run at 2 different locations. I

How to avoid code duplication implementing const and non-const iterators?

自古美人都是妖i 提交于 2019-11-27 06:22:54
I'm implementing a custom container with an STL-like interface. I have to provide a regular iterator and a const iterator. Most of the code for the two versions of the iterators is identical . How can I avoid this duplication? For example, my container class is Foo , and I'm implementating FooIterator and FooConstIterator . Both of the iterators have to provide methods like operator++() which are identical. My question is similar to How do I remove code duplication between similar const and non-const member functions? , but the answer to that one is specific to const and non-const methods,

DRY Ruby Initialization with Hash Argument

谁说胖子不能爱 提交于 2019-11-27 02:49:14
I find myself using hash arguments to constructors quite a bit, especially when writing DSLs for configuration or other bits of API that the end user will be exposed to. What I end up doing is something like the following: class Example PROPERTIES = [:name, :age] PROPERTIES.each { |p| attr_reader p } def initialize(args) PROPERTIES.each do |p| self.instance_variable_set "@#{p}", args[p] if not args[p].nil? end end end Is there no more idiomatic way to achieve this? The throw-away constant and the symbol to string conversion seem particularly egregious. Mladen Jablanović You don't need the

In Specflow can I run one test as a step of another?

最后都变了- 提交于 2019-11-26 23:14:07
问题 TL;DR; How can I create a specflow test that calls another test as its first step? Given I already have one specflow test And I want to run another test that goes deeper than the first test Then I create a second test that runs the first test as its first step And I add additional steps to test the deeper functionality Sorry, little bit of specflow humor there. eg I have a test that creates a sale already: Given I want to create a sales order And I open the sales order page And I click the

How to repeat a “block” in a django template

删除回忆录丶 提交于 2019-11-26 22:30:11
问题 I want to use the same {% block %} twice in the same django template. I want this block to appear more than once in my base template: # base.html <html> <head> <title>{% block title %}My Cool Website{% endblock %}</title> </head> <body> <h1>{% block title %}My Cool Website{% endblock %}</h1> </body> </html> And then extend it: # blog.html {% extends 'base.html' %} {% block title %}My Blog{% endblock %} # pictures.html {% extends 'base.html' %} {% block title %}My Pictures{% endblock %} # cats

How do I DRY up my CouchDB views?

て烟熏妆下的殇ゞ 提交于 2019-11-26 20:53:45
问题 What can I do to share code among views in CouchDB? Example 1 -- utility methods Jesse Hallett has some good utility methods, including function dot(attr) { return function(obj) { return obj[attr]; } } Array.prototype.map = function(func) { var i, r = [], for (i = 0; i < this.length; i += 1) { r[i] = func(this[i]); } return r; }; ... Where can I put this code so every view can access it? Example 2 -- constants Similarly for constants I use in my application. Where do I put MyApp = { A

Template function as a template argument

独自空忆成欢 提交于 2019-11-26 15:37:52
问题 I've just got confused how to implement something in a generic way in C++. It's a bit convoluted, so let me explain step by step. Consider such code: void a(int) { // do something } void b(int) { // something else } void function1() { a(123); a(456); } void function2() { b(123); b(456); } void test() { function1(); function2(); } It's easily noticable that function1 and function2 do the same, with the only different part being the internal function. Therefore, I want to make function generic

How to make a char string from a C macro&#39;s value?

ε祈祈猫儿з 提交于 2019-11-26 15:18:26
For example, how to avoid writing the 'func_name' twice? #ifndef TEST_FUN # define TEST_FUN func_name # define TEST_FUN_NAME "func_name" #endif I'd like to follow the Single Point of Truth rule. Version of C preprocessor: $ cpp --version cpp (GCC) 4.1.2 20070626 (Red Hat 4.1.2-14) Jonathan Leffler He who is Shy * gave you the germ of an answer , but only the germ. The basic technique for converting a value into a string in the C pre-processor is indeed via the '#' operator, but a simple transliteration of the proposed solution gets a compilation error: #define TEST_FUNC test_func #define TEST

Declare and initialize pointer concisely (i. e. pointer to int)

自闭症网瘾萝莉.ら 提交于 2019-11-26 14:37:34
问题 Given pointers to char, one can do the following: char *s = "data"; As far as I understand, a pointer variable is declared here, memory is allocated for both variable and data, the latter is filled with data\0 and the variable in question is set to point to the first byte of it (i. e. variable contains an address that can be dereferenced). That's short and compact. Given pointers to int, for example, one can do this: int *i; *i = 42; or that: int i = 42; foo(&i); // prefix every time to get a