Search Results

Search found 10178 results on 408 pages for 'testing metaprogramming'.

Page 21/408 | < Previous Page | 17 18 19 20 21 22 23 24 25 26 27 28  | Next Page >

  • How do I write an RSpec test to unit-test this interesting metaprogramming code?

    - by Kyle Kaitan
    Here's some simple code that, for each argument specified, will add specific get/set methods named after that argument. If you write attr_option :foo, :bar, then you will see #foo/foo= and #bar/bar= instance methods on Config: module Configurator class Config def initialize() @options = {} end def self.attr_option(*args) args.each do |a| if not self.method_defined?(a) define_method "#{a}" do @options[:"#{a}"] ||= {} end define_method "#{a}=" do |v| @options[:"#{a}"] = v end else throw Exception.new("already have attr_option for #{a}") end end end end end So far, so good. I want to write some RSpec tests to verify this code is actually doing what it's supposed to. But there's a problem! If I invoke attr_option :foo in one of the test methods, that method is now forever defined in Config. So a subsequent test will fail when it shouldn't, because foo is already defined: it "should support a specified option" do c = Configurator::Config c.attr_option :foo # ... end it "should support multiple options" do c = Configurator::Config c.attr_option :foo, :bar, :baz # Error! :foo already defined # by a previous test. # ... end Is there a way I can give each test an anonymous "clone" of the Config class which is independent of the others?

    Read the article

  • Rails Metaprogramming: How to add instance methods at runtime?

    - by Larry K
    I'm defining my own AR class in Rails that will include dynamically created instance methods for user fields 0-9. The user fields are not stored in the db directly, they'll be serialized together since they'll be used infrequently. Is the following the best way to do this? Alternatives? Where should the start up code for adding the methods be called from? class Info < ActiveRecord::Base end # called from an init file to add the instance methods parts = [] (0..9).each do |i| parts.push "def user_field_#{i}" # def user_field_0 parts.push "get_user_fields && @user_fields[#{i}]" parts.push "end" end Info.class_eval parts.join

    Read the article

  • Does software testing have a future?

    - by Firas
    Hello everybody. My current career is in software testing, but I feel that I am wasting my time, maybe because I don't know the future path of this career, and where I will arrive in the future if I continue in this career. And I don't know how can I develop myself in this career. Can I have my own job in this field? Please give me good suggestions and opinion. Many thanks.

    Read the article

  • The ultimate browser testing machine...

    - by Mazzi
    Hi All, What would be the ultimate web application browser compatibility test machine be? The testing environment would be (XP: IE6,FF3.6), (XP: IE7,Chrome), (XP: IE8,Safari), (MacOsX: Safari, FF3.6, Chrome), (Ubuntu: FF3.6, Chrome) Of course I want it all in one machine, my initial thought was Using a MacOsX as a host machine and use virtual box to install 3 xp and one ubuntu on it. Do you think it is an optimal solution? Do you have any better solution to achieve the above?

    Read the article

  • Good books and resources on user interface testing

    - by josefx
    I am looking for good books and articles on user-interface testing. What they should contain (one or more of): different test methods/strategies examples, use cases naming pros and cons for different methods something important I might have forgotten :-) What they should not be: Only about general tests and not gui tests describing a test framework limited to a single language What are the best resources you know of? (preferably language agnostic)

    Read the article

  • How do I use Ruby metaprogramming to refactor this common code?

    - by James Wenton
    I inherited a project with a lot of badly-written Rake tasks that I need to clean up a bit. Because the Rakefiles are enormous and often prone to bizarre nonsensical dependencies, I'm simplifying and isolating things a bit by refactoring everything to classes. Specifically, that pattern is the following: namespace :foobar do desc "Frozz the foobar." task :frozzify do unless Rake.application.lookup('_frozzify') require 'tasks/foobar' Foobar.new.frozzify end Rake.application['_frozzify'].invoke end # Above pattern repeats many times. end # Several namespaces, each with tasks that follow this pattern. In tasks/foobar.rb, I have something that looks like this: class Foobar def frozzify() # The real work happens here. end # ... Other tasks also in the :foobar namespace. end For me, this is great, because it allows me to separate the task dependencies from each other and to move them to another location entirely, and I've been able to drastically simplify things and isolate the dependencies. The Rakefile doesn't hit a require until you actually try to run a task. Previously this was causing serious issues because you couldn't even list the tasks without it blowing up. My problem is that I'm repeating this idiom very frequently. Notice the following patterns: For every namespace :xyz_abc, there is a corresponding class in tasks/... in the file tasks/[namespace].rb, with a class name that looks like XyzAbc. For every task in a particular namespace, there is an identically named method in the associated namespace class. For example, if namespace :foo_bar has a task :apples, you would expect to see def apples() ... inside the FooBar class, which itself is in tasks/foo_bar.rb. Every task :t defines a "meta-task" _t (that is, the task name prefixed with an underscore) which is used to do the actual work. I still want to be able to specify a desc-description for the tasks I define, and that will be different for each task. And, of course, I have a small number of tasks that don't follow the above pattern at all, so I'll be specifying those manually in my Rakefile. I'm sure that this can be refactored in some way so that I don't have to keep repeating the same idiom over and over, but I lack the experience to see how it could be done. Can someone give me an assist?

    Read the article

  • C# Unit testing resources

    - by Mohit Deshpande
    I migrated from Java to C# and so I am wondering how to unit tests in C#. I remember using JUnit to test my Java applications and importing the package, etc. How can I unit test in C#? What are some good resources for unit testing in C#?

    Read the article

  • Unit Testing in iphone i got below error.

    - by Pradeep
    whenever i run the unit testing application to find whether appdelegate is there r not using the test suit -(void)testAppDelegate { id app_delegate=[[UIApplication sharedApplication]delegate]; STAssertNotNil(app_delegate,@"delegate not found"); } i got this error. Please help. "_OBJC_CLASS_$_UIApplication", referenced from: objc-class-ref-to-UIApplication in Tests.o ld: symbol(s) not found collect2: ld returned 1 exit status

    Read the article

  • IIS Integration testing: remove X-Powered-By: ASP.NET header

    - by stacker
    I want to have a test that testing the inexistent of this http headers, using NAnt and NUnit: X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Edit: I'm asking hot to actually test this rule: "don't have asp headers". so, I can have this test in each new website that I'm doing, so it make it easier no to forget this simple step.

    Read the article

  • Unit Testing XQuery

    - by toddk
    I've been working with a document repository using XQuery (via Java and .NET interfaces) and was wondering if anyone has any recommendations for unit testing XQuery modules?

    Read the article

  • Software testing terminology

    - by shiouming
    Let say I have written a small program that reads file_A and file_B as input data of test_case_A and test_case_B, passes the input to component_X which needs to be test, then verifies result against predefined expectation. That component_X could be in the same process, or different process on another machine. I try to learn more about testing, but confused by various terms. Take above scenario as example, which of them is fixture/mock/harness/stub? Thanks.

    Read the article

  • UI Testing Tool on linux

    - by Hulk
    Looking for a tool to UI testing on Linux .Platform used for development is django. The idea is that the analysts will capture the tests thru some UI and it will be able to be played back over and over again.

    Read the article

  • Multi language testing framework

    - by santiiiii
    I need to write two versions of the same application, one in .NET and the other one in Java. So I'd like to write a single test suite, and then use it against both codebases. Which testing tool would you advise me to use?

    Read the article

  • How can one make a 'passthru' function in C++ using macros or metaprogramming?

    - by Ryan
    So I have a series of global functions, say: foo_f1(int a, int b, char *c); foo_f2(int a); foo_f3(char *a); I want to make a C++ wrapper around these, something like: MyFoo::f1(int a, int b, char* c); MyFoo::f2(int a); MyFoo::f3(char* a); There's about 40 functions like this, 35 of them I just want to pass through to the global function, the other 5 I want to do something different with. Ideally the implementation of MyFoo.cpp would be something like: PASSTHRU( f1, (int a, int b, char *c) ); PASSTHRU( f2, (int a) ); MyFoo::f3(char *a) { //do my own thing here } But I'm having trouble figuring out an elegant way to make the above PASSTHRU macro. What I really need is something like the mythical X getArgs() below: MyFoo::f1(int a, int b, char *c) { X args = getArgs(); args++; //skip past implicit this.. ::f1(args); //pass args to global function } But short of dropping into assembly I can't find a good implementation of getArgs().

    Read the article

  • How do you extend a Ruby module with macro-like metaprogramming methods?

    - by Ian Terrell
    Consider the following extension (the pattern popularized by several Rails plugins over the years): module Extension def self.included(recipient) recipient.extend ClassMethods recipient.class_eval { include InstanceMethods } end module ClassMethods def macro_method puts "Called macro_method within #{self.name}" end end module InstanceMethods def instance_method puts "Called instance_method within #{self.object_id}" end end end If you wished to expose this to every class, you can do the following: Object.send :include, Extension Now you can define any class and use the macro method: class FooClass macro_method end #=> Called macro_method within FooClass And instances can use the instance methods: FooClass.new.instance_method #=> Called instance_method within 2148182320 But even though Module.is_a?(Object), you cannot use the macro method in a module: module FooModule macro_method end #=> undefined local variable or method `macro_method' for FooModule:Module (NameError) This is true even if you explicitly include the original Extension into Module with Module.send(:include, Extension). How do you add macro like methods to Ruby modules?

    Read the article

  • Unit testing http handlers?

    - by MockedMan.Object
    My current project based in Asp .net makes considerable use of Http handlers to process various requests? So, is there any way by which I can test the functionality of each of the handlers using unit test cases? We are using Nunit and Moq framework to facilitate unit testing.

    Read the article

< Previous Page | 17 18 19 20 21 22 23 24 25 26 27 28  | Next Page >