Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 178763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:17:16+00:00 2026-05-11T14:17:16+00:00

I am working on a testing framework for the software that my company writes.

  • 0

I am working on a testing framework for the software that my company writes. Our product is web based and After I run a RESTful request I want to process the results. I want to be able to have activerecord type validations in each command class so that after it is run the results are automatically tested against all the ‘validations’. However, I am not sure how to do this. My code looks like this (simplified to show the important parts).

class CodesecureCommand   def execute     result = RestClient.post('http://#{codesecure.host_name_port}#{path}', post_data)      return parse(result) #parse simple returns a Hpricot document   end end  class RunScan < CodesecureCommand    #What I have now   #I have to override the execute function so that it calls the local success method   #to see if it failed or not.   def execute()     result = super()      if success(result)       return true     else     end    end    def success(result)     result.search('div.transaction-message') do |message|       if message.innerHTML.scan(/Configure abuse setting for domain users successfully\./).length == 1         return true       end     end   end      #What I would like is to be able to call execute (without having to override it).   #then after it runs it calls back to this class to check    #if the regex matches the command was successful and returns true   test_success /regex/    #if test_success fails then these are called   #the idea being that I can use the regex to identify errors that happened then   #report them to the user   identify_error /regex/, 'message'   identify_error /regex/, 'message'   end end 

What I want is that after the execute method is called the test_success and identify_error are automatically called like the validations in activerecord. Can anybody tell me how to do this? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:17:17+00:00Added an answer on May 11, 2026 at 2:17 pm

    Without having looked much at your code, here’s my take on implementing validation class methods:

    module Validations   def self.included(base)     base.extend ClassMethods   end    def validate     errors.clear     self.class.validations.each {|validation| validation.call(self) }   end    def valid?     validate     errors.blank?   end    def errors     @errors ||= {}   end    module ClassMethods     def validations       @validations ||= []     end      def validates_presence_of(*attributes)       validates_attributes(*attributes) do |instance, attribute, value, options|         instance.errors[attribute] = 'cant't be blank' if value.blank?       end     end      def validates_format_of(*attributes)       validates_attributes(*attributes) do |instance, attribute, value, options|         instance.errors[attribute] = 'is invalid' unless value =~ options[:with]       end     end      def validates_attributes(*attributes, &proc)       options = attributes.extract_options!        validations << Proc.new { |instance|         attributes.each {|attribute|           proc.call(instance, attribute, instance.__send__(attribute), options)         }       }     end   end end 

    It assumes that ActiveSupport is around, which it is in a Rails environment. You might want to extend it to allow multiple errors per attribute, with instance.errors[attribute] << 'the message', but I left out obscurities like that in order to keep this short sample as simple as possible.

    Here’s a short usage example:

    class MyClass   include Validations    attr_accessor :foo   validates_presence_of :foo   validates_format_of :foo, :with => /^[a-z]+$/ end  a = MyClass.new puts a.valid? # => false  a.foo = 'letters' puts a.valid? # => true  a.foo = 'Oh crap$(!)*#' puts a.valid? # => false 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 85k
  • Answers 85k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Binding to tags as the model key path attempts to… May 11, 2026 at 5:08 pm
  • Editorial Team
    Editorial Team added an answer I often have this myself. You start working on a… May 11, 2026 at 5:08 pm
  • Editorial Team
    Editorial Team added an answer Don't try to parse XML with regular expressions; it leads… May 11, 2026 at 5:08 pm

Related Questions

I am working on a software development project that uses code written primarily in
Currently, I am working on a new version control system as part of a
Coming from a corporate IT environment, the standard was always creating a class library
OK, I know there have already been questions about getting started with TDD ..

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.