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

  • SEARCH
  • Home
  • 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 4072638
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:54:37+00:00 2026-05-20T16:54:37+00:00

I’ve built an important MySQL database, with a lot of view, triggers, functions and

  • 0

I’ve built an important MySQL database, with a lot of view, triggers, functions and procedures.

It’s very hard to test, and to not forget anything, so, I’ve written Cucumber scenarios for all of the features of my DB (Insert, Select, etc., request on functions an procedures etc., and views)

This help us a lot when we test the behavior of all this, and even before writing view and other code, it’s very helpful to determinate want we really want to do.

My problem is: after writing Cucumber features, we all test by hand in a MySQL Shell.

I’m new in BDD/TDD and Agile methods, but I’ve done some search to know how to make some automation, but found nothing very interesting for my case.

Is there somebody who can provide some interesting way to create automation for this?

I don’t know Ruby, but by example, is it possible to use RSPec directly with MySQL (with some examples)?

Or in another language, or any solution you can think of!

Thanks in advance!

[EDIT]


If found some interesting things with RSpec and MySQL:

Mysql Support For Cucumber Nagios

mysql_steps.rb


My problem is: I don’t have any knoledge with Ruby, RSPec, etc.

I’m working on it with the excellent “Pick Axe” book, and RSPec book from PragProg

But I will be very grateful for a little example of of RSpec steps given the code below:


The MySQL Procedure

DELIMITER $$

CREATE PROCEDURE `prc_liste_motif` (
    IN texte TEXT,
    IN motif VARCHAR(255),
    OUT nb_motif INT(9),
    OUT positions TEXT)
BEGIN
    DECLARE ER_SYNTAXE CONDITION FOR SQLSTATE '45000';
    DECLARE sousChaine TEXT;
    DECLARE positionActuelle INT(9) DEFAULT 1;
    DECLARE i INT(9) DEFAULT 1;

    IF
        LENGTH(motif) > LENGTH(texte)
    THEN
        SIGNAL ER_SYNTAXE
            SET MESSAGE_TEXT =
              'Bad Request: Le motif est plus long que le texte.',
              MYSQL_ERRNO = 400;
    END IF;

    SET positions = '';
    SET nb_motif = 0;

    REPEAT

        SET sousChaine = SUBSTRING_INDEX(texte, motif, i);

        SET positionActuelle = LENGTH(sousChaine) + 1;

        IF
          positionActuelle < LENGTH(texte) + 1
        THEN

            IF
              LENGTH(positions) > 0
            THEN
                SET positions = CONCAT(positions, ',');
            END IF;

            SET positions = CONCAT(positions, positionActuelle);

            SET nb_motif = nb_motif + 1;

        END IF;

        SET i = i + 1;

    UNTIL LENGTH(sousChaine) >= LENGTH(texte)
    END REPEAT;

END$$

The Cucumber feature:

Feature: Procedure prc_liste_motif
  In order to precess a string according to a given unit
  I want to know the number of units present in the chain and their positions
  Knowing that the index starts at 1

  Background: the database mydatabase in our SGBDR server
    Given I have a MySQL server on 192.168.0.200
    And I use the username root
    And I use the password xfe356
    And I use the database mydatabase

  Scenario Outline: Using the procedure with good values in parameters
    Given I have a procedure prc_liste_motif
    And I have entered <texte> for the first parameter
    And I have entered <motif> for the second parameter
    And I have entered <nb_motif> for the third parameter
    And I have entered <positions> for the fourth parameter
    When I call prc_liste_motif
    Then I should have <out_nb_motif> instead of <nb_motif>
    Then I should have <out_positions> instead of <positions>

    Exemples:
      | texte         | motif | nb_motif | positions | out_nb_motif | out_positions |
      | Le beau chien | e     |          |           | 3            | 2,5,12        |
      | Allo          | ll    |          |           | 1            | 2             |
      | Allo          | w     |          |           | 0            |               |

An exemple of passed test by hand in MySQL:

$ mysql -h 192.168.0.200 -u root -p xfe356
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.9 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> USE mydatabase
Database changed
mysql> SET @texte = 'Le beau chien';
Query OK, 0 rows affected (0.00 sec)

mysql> SET @motif = 'e';
Query OK, 0 rows affected (0.00 sec)

mysql> SET @nb_motif = NULL;
Query OK, 0 rows affected (0.00 sec)

mysql> SET @positions = NULL;
Query OK, 0 rows affected (0.00 sec)

mysql> SET @out_nb_motif = 3;
Query OK, 0 rows affected (0.00 sec)

mysql> SET @out_positions = '2,5,12';
Query OK, 0 rows affected (0.00 sec)

mysql> CALL prc_liste_motif(@texte, @motif, @nb_motif, @positions);
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT @nb_motif = @out_nb_motif AND @positions = @out_positions;
+-----------------------------------------------------------+
| @nb_motif = @out_nb_motif AND @positions = @out_positions |
+-----------------------------------------------------------+
|                                                         1 |
+-----------------------------------------------------------+
1 row in set (0.00 sec)

thanks in advance for your help !

  • 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. Editorial Team
    Editorial Team
    2026-05-20T16:54:38+00:00Added an answer on May 20, 2026 at 4:54 pm

    Here is some pseudocode for one way you could test your database with RSpec:

    describe "prc_liste_motif" do
      before(:all) do
        # Set up database connection here
      end
    
      describe "good values" do
        context "Le beau chien" do
          let(:texte) { "Le beau chien" }
          # Set up other variables here
          let(:results) { # call prc_liste_motif here }
    
          it "has the correct out_nb_motif" do
            out_nb_motif = # however you derive this from the results of the procedure
            out_nb_motif.should == 3
          end
    
          it "has the correct out_positions" do
            # test out_positions here
          end
        end
      end
    end
    

    One thing I noticed in your sample manual test was how you are checking the results:

     SELECT @nb_motif = @out_nb_motif AND @positions = @out_positions;
    

    This will tell you whether or not those two values are correct, but if you get 0 results for this query, you do not immediately know which of the two values is incorrect and you do not know what the value you are getting instead is; getting that information requires more investigation.

    By splitting up the checking for these two values into 2 RSpec tests, when the tests have finished running you can know if both are correct, if one is incorrect, or if both are incorrect. If one or both are incorrect, RSpec will also return a message for the failed test that says “Expected 3, got 4” which can help you debug faster.

    As you add more tests for different inputs, I recommend refactoring the pseudocode I’ve given here to use shared_examples_for. The PragProg RSpec book that you’re already reading is a great reference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.