Browse Source

Add Ecukes tests

master
Nicolas Petton 2 years ago
parent
commit
11c8a0cc7b
Signed by untrusted user: nico GPG Key ID: 233587A47C207910
9 changed files with 358 additions and 4 deletions
  1. +1
    -0
      .gitignore
  2. +2
    -2
      Cask
  3. +5
    -2
      elbank-report.el
  4. +18
    -0
      elbank.el
  5. +182
    -0
      features/elbank-report.feature
  6. +42
    -0
      features/step-definitions/elbank-steps.el
  7. +96
    -0
      features/support/env.el
  8. +10
    -0
      features/support/test-helper.el
  9. +2
    -0
      run-tests.sh

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
.cask

+ 2
- 2
Cask View File

@@ -3,11 +3,11 @@
(package-file "elbank.el")

(development
(depends-on "ert")
(depends-on "ecukes")
(depends-on "espuds")
(depends-on "flycheck")
(depends-on "flycheck-cask")
(depends-on "f")
(depends-on "ecukes")
(depends-on "ert-runner")
(depends-on "el-mock")
(depends-on "cask-package-toolset")


+ 5
- 2
elbank-report.el View File

@@ -169,7 +169,9 @@ Transactions are grouped by the GROUP-BY column when non-nil.
Transactions are sorted by the SORT-BY column, or by the first
column if nil.

When a PERIOD is provided, append a sum row to the report."
When a PERIOD is provided, append a sum row to the report.

Return the report buffer."
(interactive)
(let ((buf (generate-new-buffer "*elbank report*")))
(pop-to-buffer buf)
@@ -187,7 +189,8 @@ When a PERIOD is provided, append a sum row to the report."
(elbank-report-filter-account)
(elbank-report-filter-period)
(elbank-report-filter-category)))
(elbank-report-refresh)))
(elbank-report-refresh)
buf))

(defun elbank-report-filter-category ()
"Prompt for a category and update the report buffer."


+ 18
- 0
elbank.el View File

@@ -42,6 +42,24 @@

;;; Code:


;; HACK: In Emacs 25.1, an older version of seq.el is provided, which can be
;; loaded before indium or even package.el. If this happens, the feature `seq'
;; being already provided, the correct version of seq.el won't get loaded.
(require 'seq)
(unless (fboundp 'seq-map-indexed)
(defun seq-map-indexed (function sequence)
"Return the result of applying FUNCTION to each element of SEQUENCE.
Unlike `seq-map', FUNCTION takes two arguments: the element of
the sequence, and its index within the sequence."
(let ((index 0))
(seq-map (lambda (elt)
(prog1
(funcall function elt index)
(setq index (1+ index))))
sequence))))


(require 'button)
(require 'tabulated-list)
(eval-and-compile (require 'cl-lib))


+ 182
- 0
features/elbank-report.feature View File

@@ -0,0 +1,182 @@
Feature: Display reports

Scenario: Reporting all transactions
When I make a full report
Then I should see:
"""
Date Label Category Amount
══════════════════════════════════════════════════════════════
2017-11-01 Rent Expenses:Rent -450.00
2017-11-18 CB Restaurant Expenses:Food -31.00
2017-11-20 Paycheck Income:Salary 2300.00
2017-11-20 Bakery xxx Expenses:Food -4.25
2017-11-24 CB Supermarket 1 Expenses:Food -124.00
"""

Scenario: Reporting all transactions within a month
When I make a monthly report
Then I should see:
"""
Period: November 2017
Date Label Category Amount
══════════════════════════════════════════════════════════════
2017-11-01 Rent Expenses:Rent -450.00
2017-11-18 CB Restaurant Expenses:Food -31.00
2017-11-20 Paycheck Income:Salary 2300.00
2017-11-20 Bakery xxx Expenses:Food -4.25
2017-11-24 CB Supermarket 1 Expenses:Food -124.00
══════════════════════════════════════════════════════════════
1690.75
"""

Scenario: Sort column
When I make a monthly report with ":sort-by amount"
Then I should see:
"""
Period: November 2017
Date Label Category Amount
══════════════════════════════════════════════════════════════
2017-11-01 Rent Expenses:Rent -450.00
2017-11-24 CB Supermarket 1 Expenses:Food -124.00
2017-11-18 CB Restaurant Expenses:Food -31.00
2017-11-20 Bakery xxx Expenses:Food -4.25
2017-11-20 Paycheck Income:Salary 2300.00
══════════════════════════════════════════════════════════════
1690.75
"""

Scenario: Reverting the sort order
When I make a monthly report with ":sort-by amount"
And I press "s"
Then I should see:
"""
Period: November 2017
Date Label Category Amount
══════════════════════════════════════════════════════════════
2017-11-20 Paycheck Income:Salary 2300.00
2017-11-20 Bakery xxx Expenses:Food -4.25
2017-11-18 CB Restaurant Expenses:Food -31.00
2017-11-24 CB Supermarket 1 Expenses:Food -124.00
2017-11-01 Rent Expenses:Rent -450.00
══════════════════════════════════════════════════════════════
1690.75
"""

Scenario: Grouping
When I make a monthly report with ":group-by category"
Then I should see:
"""
Period: November 2017
Date Label Category Amount
══════════════════════════════════════════════════════════════
Expenses:Food
──────────────────────────────────────────────────────────────
2017-11-18 CB Restaurant Expenses:Food -31.00
2017-11-20 Bakery xxx Expenses:Food -4.25
2017-11-24 CB Supermarket 1 Expenses:Food -124.00
──────────────────────────────────────────────────────────────
-159.25
Expenses:Rent
──────────────────────────────────────────────────────────────
2017-11-01 Rent Expenses:Rent -450.00
──────────────────────────────────────────────────────────────
-450.00
Income:Salary
──────────────────────────────────────────────────────────────
2017-11-20 Paycheck Income:Salary 2300.00
──────────────────────────────────────────────────────────────
2300.00
══════════════════════════════════════════════════════════════
1690.75
"""

Scenario: Grouping and sorting reports
When I make a monthly report with ":group-by category :sort-by amount"
Then I should see:
"""
Period: November 2017
Date Label Category Amount
══════════════════════════════════════════════════════════════
Expenses:Rent
──────────────────────────────────────────────────────────────
2017-11-01 Rent Expenses:Rent -450.00
──────────────────────────────────────────────────────────────
-450.00
Expenses:Food
──────────────────────────────────────────────────────────────
2017-11-24 CB Supermarket 1 Expenses:Food -124.00
2017-11-18 CB Restaurant Expenses:Food -31.00
2017-11-20 Bakery xxx Expenses:Food -4.25
──────────────────────────────────────────────────────────────
-159.25
Income:Salary
──────────────────────────────────────────────────────────────
2017-11-20 Paycheck Income:Salary 2300.00
──────────────────────────────────────────────────────────────
2300.00
══════════════════════════════════════════════════════════════
1690.75
"""

Scenario: Selecting columns
When I make a monthly report with ":columns (date label amount)"
Then I should see:
"""
Period: November 2017
Date Label Amount
═════════════════════════════════════════════
2017-11-01 Rent -450.00
2017-11-18 CB Restaurant -31.00
2017-11-20 Paycheck 2300.00
2017-11-20 Bakery xxx -4.25
2017-11-24 CB Supermarket 1 -124.00
═════════════════════════════════════════════
1690.75
"""

Scenario: Filtering by category
When I make a monthly report
And I press "fcExpenses:Food"
Then I should see:
"""
Period: November 2017
Category: Expenses:Food
Date Label Category Amount
══════════════════════════════════════════════════════════════
2017-11-18 CB Restaurant Expenses:Food -31.00
2017-11-20 Bakery xxx Expenses:Food -4.25
2017-11-24 CB Supermarket 1 Expenses:Food -124.00
══════════════════════════════════════════════════════════════
-159.25
"""

Scenario: Filtering by category
When I make a monthly report
And I press "fcExpenses"
Then I should see:
"""
Period: November 2017
Category: Expenses
Date Label Category Amount
══════════════════════════════════════════════════════════════
2017-11-01 Rent Expenses:Rent -450.00
2017-11-18 CB Restaurant Expenses:Food -31.00
2017-11-20 Bakery xxx Expenses:Food -4.25
2017-11-24 CB Supermarket 1 Expenses:Food -124.00
══════════════════════════════════════════════════════════════
-609.25
"""

+ 42
- 0
features/step-definitions/elbank-steps.el View File

@@ -0,0 +1,42 @@
;; This file contains your project specific step definitions. All
;; files in this directory whose names end with "-steps.el" will be
;; loaded automatically by Ecukes.

(When "^I make a full report$"
(lambda ()
(switch-to-buffer (elbank-report))))

(When "^I make a monthly report$"
(lambda ()
(switch-to-buffer (elbank-report
:period `(month ,@(last (elbank-transaction-months)))))))

(When "^I make a monthly report with \"\\(.+\\)\"$"
(lambda (options)
(switch-to-buffer (apply #'elbank-report
:period `(month ,@(last (elbank-transaction-months)))
(read (format "(%s)" options))))))

(Given "^I have \"\\(.+\\)\"$"
(lambda (options)
))

(When "^I have \"\\(.+\\)\"$"
(lambda (something)
;; ...
))

(Then "^I should have \"\\(.+\\)\"$"
(lambda (something)
;; ...
))

(And "^I have \"\\(.+\\)\"$"
(lambda (something)
;; ...
))

(But "^I should not have \"\\(.+\\)\"$"
(lambda (something)
;; ...
))

+ 96
- 0
features/support/env.el View File

@@ -0,0 +1,96 @@
(require 'f)
(require 'subr-x)

(defvar elbank-support-path
(f-dirname load-file-name))

(defvar elbank-features-path
(f-parent elbank-support-path))

(defvar elbank-root-path
(f-parent elbank-features-path))

(add-to-list 'load-path elbank-root-path)

;; Ensure that we don't load old byte-compiled versions
(let ((load-prefer-newer t))
(require 'elbank)
(require 'espuds)
(require 'ert))

(Setup
;; Before anything has run
(setq real-elbank-data elbank-data)
(setq elbank-data
'((accounts . [((id . "1234@fakebank")
(label . "Fake account 1")
(currency . "EUR")
(iban . "1234")
(type . 1)
(balance . "400"))

((id . "1235@fakebank")
(label . "Fake account 2")
(currency . "EUR")
(iban . "1235")
(type . 1)
(balance . "50"))])
(transactions
(1234@fakebank . [((id . "@fakebank")
(date . "2017-11-24")
(rdate . "2017-11-24")
(type . 1)
(raw . "CB Supermarket 1")
(label . "CB Supermarket 1")
(amount . "-124.00"))
((id . "@fakebank")
(date . "2017-11-20")
(rdate . "2017-11-20")
(type . 1)
(label . "Paycheck")
(raw . "Transfer company XX paycheck")
(amount . "2300.00"))
((id . "@fakebank")
(date . "2017-11-20")
(rdate . "2017-11-20")
(type . 1)
(raw . "Bakery xxx")
(label . "Bakery xxx")
(amount . "-4.25"))
((id . "@fakebank")
(date . "2017-11-18")
(rdate . "2017-11-18")
(type . 1)
(raw . "CB Restaurant")
(label . "CB Restaurant")
(amount . "-31.00"))
((id . "@fakebank")
(date . "2017-11-01")
(rdate . "2017-11-01")
(type . 1)
(label . "Rent")
(raw . "Rent November 2017")
(amount . "-450.00"))]))))

(setq real-elbank-categories elbank-categories)
(setq elbank-categories '(("Expenses:Food" . ("supermarket"
"restaurant"
"Local store"
"Bakery"))
("Expenses:Rent" . ("rent"))
("Income:Salary" . ("company xx")))))

(Before
;; Before each scenario is run
)

(After
;; After each scenario is run
)

(Teardown
;; After when everything has been run
(setq elbank-data real-elbank-data)
(setq elbank-categories real-elbank-categories)
(when-let ((buf (get-buffer "*elbank-report*")))
(kill-buffer buf)))

+ 10
- 0
features/support/test-helper.el View File

@@ -0,0 +1,10 @@
;; Temporary fix for https://github.com/ecukes/ecukes/issues/170
(when (require 'cl-preloaded nil t)
(setf (symbol-function 'cl--assertion-failed)
(lambda (form &optional string sargs args)
"Fake version"
;; (if debug-on-error
;; (apply debugger `(cl-assertion-failed ,form ,string ,@sargs))
(if string
(apply #'error string (append sargs args))
(signal 'cl-assertion-failed `(,form ,@sargs))))))

+ 2
- 0
run-tests.sh View File

@@ -0,0 +1,2 @@
#!/bin/sh -e
cask exec ecukes "$@"

Loading…
Cancel
Save