{"id":15240487,"url":"https://github.com/mountainfield/uspec","last_synced_at":"2025-04-10T13:43:10.760Z","repository":{"id":62586781,"uuid":"244257641","full_name":"MountainField/uspec","owner":"MountainField","description":null,"archived":false,"fork":false,"pushed_at":"2023-02-05T12:25:28.000Z","size":22,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-24T12:21:47.976Z","etag":null,"topics":["bdd","bdd-specs","bdd-style","bdd-style-testing-framework","python","rspec","test-driven-development","test-framework","testing-framework","testing-tools"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MountainField.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-02T01:57:49.000Z","updated_at":"2023-09-12T13:20:14.000Z","dependencies_parsed_at":"2023-02-18T23:31:06.459Z","dependency_job_id":null,"html_url":"https://github.com/MountainField/uspec","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MountainField%2Fuspec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MountainField%2Fuspec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MountainField%2Fuspec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MountainField%2Fuspec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MountainField","download_url":"https://codeload.github.com/MountainField/uspec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248226305,"owners_count":21068179,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bdd","bdd-specs","bdd-style","bdd-style-testing-framework","python","rspec","test-driven-development","test-framework","testing-framework","testing-tools"],"created_at":"2024-09-29T11:05:13.840Z","updated_at":"2025-04-10T13:43:10.739Z","avatar_url":"https://github.com/MountainField.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# USpec\n\n\n[USpec](https://github.com/MountainField/uspec) is a 'Domain Specific Language' (DSL) testing tool written in Python to test Python code in a 'Behavior-Driven Development' (BDD) mannar.\n\n- Alomost the same grammar as [Rspec](https://rspec.info) \n- Alternative representaiotn of a test case of [unittest](https://docs.python.org/3/library/unittest.html). Since Uspec file can be tested by unittest, Developers can gradually migrate existing unittests to USpec.\n\n## What is USpec?\n\n### USpec has the alomost the same grammar as RSpec\n\nLet's assume that [Bowling class](https://rspec.info) calculates the sum of game scores if there is no strikes and spares.\n\n- `bowling.py`\n\n    ```python\n\tclass Bowling(object):\n\t    \n\t    def __init__(self):\n\t        self._score = 0\n\t    \n\t    def hit(self, pins):\n\t        self._score += pins\n\t\n\t    def score(self):\n\t        return self._score\n    ```\n\nFor example, the instance of the Bowling class returns 80 for 20 same hit numbers 4, 4, ... , 4.\nThis example can be written in `bowling_spec.rb` by [Rspec file](https://rspec.info) which is the most common BDD tool.\nUsing [USpec](https://github.com/MountainField/uspec), we can write a spec Python file `bowling_spec.py` equivalent to `bowling_spec.rb` \n\n- `bowling_spec.rb`\n\n\t```ruby\n\tRSpec.describe Bowling, \"#score\" do\n\t    context \"with no strikes or spares\" do\n\t        it \"sums the pin count for each roll\" do\n\t            bowling = Bowling.new\n\t            20.times { bowling.hit(4) }\n\t            expect(bowling.score).to eq 80\n\t        end\n\t    end\n\tend\n\t```\n\t\n- `bowling_spec.py`\n\t\n\t```python\n\tfrom uspec import description, context, it\n\t\n\twith description(Bowling, \"#score\"):\n\t    with context(\"with no strikes or spaces\"):\n\t        @it(\"sums the pin count for each roll\")\n\t        def _(self):\n\t            bowling = Bowling()\n\t            for i in range(20): bowling.hit(4)\n\t            self.assertEqual(bowling.score(), 80)\n\t```\n\n### Uspec file is an alternative representation of unittest file\n\nWhen a Uspec file is loaded by Python runtime, it generates a sub class of `unittest.TestCase` in that place.\n\n- The equivalent test case of the USpec file `bowling_spec.py` above benerated by USpec is:\n\n\t```python\n\timport unittest\n\tclass TestBowling_Score__WithNoStrikesOrSpaces(unittest.TestCase):\n\t    def test_sums_the_pin_count_for_each_roll(self):\n\t        bowling = Bowling()\n\t        for i in range(20):\n\t            bowling.hit(4)\n\t        self.assertEqual(bowling.score(), 80)\n\t```\n\n### Uspec file can be tested by unittest\n\n- Uspec file behaves as if it was written in unittest format, so it can be tested by unittest below:\n\n\t```\n\t$ python -m unittest -v bowling_spec.py \n\ttest0000: Bowling#score (with no strikes or spaces) sums the pin count for each roll (uspec.TestBowling#score) ... ok\n\t\n\t----------------------------------------------------------------------\n\tRan 1 tests in 0.000s\n\t\n\tOK\n\t```\n\n- Mix of Uspec files and unittest files can be also tested by unittest.\nAssume that `test_baseball.py` is the traditional unittest file.\nSince `bowling_spec.py` and` test_baseball.py` can be processed simultaneously by unittest, The total count of test cases becomes sum of test case of these files: \n\n\t```\n\t$ python -m unittest -v bowling_spec.py   test_baseball.py\n\ttest0000: Bowling#score (with no strikes or spaces) sums the pin count for each roll (uspec.TestBowling#score) ... ok\n\ttest_game_countes (test_baseball.py.TestBaseball) ... ok\n\t\n\t----------------------------------------------------------------------\n\tRan 2 tests in 0.000s\n\t\n\tOK\n\t```\n\n\n\nUsage\n-----\n\n\n\n\nAuthor\n------\n\n- **Takahide Nogayama** - [Nogayama](https://github.com/nogayama)\n\n\n\nLicense\n-------\n\nThis project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details\n\n\n\nContributing\n------------\n\nPlease read [CONTRIBUTING.md](./CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmountainfield%2Fuspec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmountainfield%2Fuspec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmountainfield%2Fuspec/lists"}